Arrays: 7.More Arrays Methods exercise


#1

This doesn’t have sense, if there are 7 items, taking in count that ‘orange juice’ is replaced by ‘popcorn’, then why in the console.log (groceryList.slice(1, 4)); the function only cuts 1 and 4 but when I run the program it cuts 5,6 and 7?

let groceryList = [‘orange juice’, ‘bananas’, ‘coffee beans’, ‘brown rice’, ‘pasta’, ‘coconut oil’, ‘plantains’];

groceryList.shift();
console.log(groceryList);

groceryList.unshift(‘popcorn’);
console.log(groceryList);

console.log(groceryList.slice(1, 4));

The results are
[ ‘bananas’,
‘coffee beans’,
‘brown rice’,
‘pasta’,
‘coconut oil’,
‘plantains’ ]
[ ‘popcorn’,
‘bananas’,
‘coffee beans’,
‘brown rice’,
‘pasta’,
‘coconut oil’,
‘plantains’ ]
[ ‘bananas’, ‘coffee beans’, ‘brown rice’ ]


#2

What do you mean with:

Where do you run the program?

The exercise is to use the .slice() method and console.log 3 items from the groceryList and that’s working right?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.