Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const groceryList = ['orange juice', 'bananas', 'coffee beans', 'brown rice', 'pasta', 'coconut oil', 'plantains'];
- // remove the first item using shift
- groceryList.shift()
- console.log(groceryList);
- // add 'popcorn' to the front of the array using unshift
- groceryList.unshift('popcorn');
- console.log(groceryList);
- // extract a part of the array based on start and end position (non-inclusive)
- console.log(groceryList.slice(1,4));
- // shows that the list is non-mutated after performing a slice operation
- console.log(groceryList);
- // find the index of a particular element using indexOf
- const pastaIndex = groceryList.indexOf('pasta');
- console.log(pastaIndex);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement