JavaScript Array Methods
Adding and Removing Elements
Methods to add or remove elements from the beginning or end of an array.
push(): Adds element to endpop(): Removes element from endunshift(): Adds element to beginningshift(): Removes element from beginning
Slicing and Splicing
slice() extracts a part of an array and returns a new array
(does not modify original).
splice() adds/removes items to/from an array (modifies
original).
High-Order Array Methods
These methods take a function as an argument and are very powerful for data manipulation.
map()
Creates a new array by performing a function on each array element.
filter()
Creates a new array with all array elements that pass a test.
reduce()
Runs a function on each array element to produce (reduce it to) a single value.
Summary
push/popwork on the end of the array.unshift/shiftwork on the beginning of the array.maptransforms every element.filterselects a subset of elements.reducecombines elements into a single value.- These methods (especially map/filter/reduce) are essential for modern JavaScript (React, Vue, etc.).
Quick Quiz
Which method creates a NEW array with the results of calling a function for every array element?
Enjoying these tutorials?