DEV Community

talent
talent

Posted on

Javascript Arrays

In JavaScript, an array is a type of data structure that is used to store a collection of values. An array is defined using square brackets, and its elements are separated by commas.

JavaScript provides many methods for working with arrays. Some of the most commonly used methods are:

1 push(): adds one or more elements to the end of an array.
2 pop(): removes the last element from an array.
3 shift(): removes the first element from an array.
4 unshift(): adds one or more elements to the beginning of an array.
5 slice(): returns a new array containing a portion of an existing array.
6 splice(): adds or removes elements from an array at a specified index.
7 concat(): joins two or more arrays together.
8 indexOf(): returns the index of the first occurrence of a specified element in an array.
9 lastIndexOf(): returns the index of the last occurrence of a specified element in an array.
10 forEach(): executes a provided function once for each element in an array.
11 map(): creates a new array with the results of calling a provided function on every element in an array.
12 filter(): creates a new array with all elements that pass a provided test.
13 reduce(): applies a provided function to each element of an array and returns a single value
.

Top comments (0)