Array Transformations
Learn about different array-related methods in JavaScript.
We will take the food
array we created in the previous lesson and use some array-related methods on it.
food = ['Coconut', 'Pineapple', 'Melon', 'Burger', 'Fries', 'Cookie', 'Popcorn', 'Coffee' ]
Slicing and splicing
The slice()
method creates a subarray, effectively chopping out a slice of an
original array starting at one position and finishing at another. For example, if
we wanted to find the third and fourth items in our food
array, we would use the following code:
Get hands-on with 1400+ tech skills courses.