bradxr
8/5/2018 - 6:03 AM

Copy Array Items Using Slice()

Doesn't modify array elements directly but extracts them to a new array Takes 2 parameters: the index to begin extraction, the index to stop extraction

let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear'];

let todaysWeather = weatherConditions.slice(1, 3);
// todaysWeather equals ['snow', 'sleet'];
// weatherConditions still equals ['rain', 'snow', 'sleet', 'hail', 'clear']