The JavaScript Array object is a global object that is used in the construction of arrays and has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. JavaScript arrays are zero-indexed: the first element of an array is at index 0, and the last element is at the index equal to the value of the array’s length property minus 1.

See the Pen thecodelog.com - JS Arrays 2 1 by Deano (@deangilewicz) on CodePen.

The following methods DO NOT manipulate the array. 1. To check if an item exists within an array the indexOf() method can be used. If found, the index of the first item equal to the specified value is returned. If not found -1 is returned:

See the Pen thecodelog.com - JS Arrays 2 2 by Deano (@deangilewicz) on CodePen.

2. The lastIndexOf() method can be used to return the index of the last item equal to the specified value. If not found -1 is returned:

See the Pen thecodelog.com - JS Arrays 2 3 by Deano (@deangilewicz) on CodePen.

3. Accessing an array item directly using bracket notation returns the value of the item at that index. When an item at a specific index does not exist undefined is returned:

See the Pen thecodelog.com - JS Arrays 2 4 by Deano (@deangilewicz) on CodePen.

4. The join() methods joins all items of an array into a string. An optional separator value can be passed to separate each item of the array:

See the Pen thecodelog.com - JS Arrays 2 5 by Deano (@deangilewicz) on CodePen.

5. The slice() method returns a shallow copy of a portion of an array into a new array object selected from beginning to end (end not included):

See the Pen thecodelog.com - JS Arrays 2 6 by Deano (@deangilewicz) on CodePen.

The following methods change the position of the items in the array. 1. The sort() method sorts the items of an array in place and returns the array. By default the sort order is according to string Unicode code points. However, a compareFunction can be passed an an argument and will be used instead if present:

See the Pen thecodelog.com - JS Arrays 2 7 by Deano (@deangilewicz) on CodePen.

2. The reverse() method reverses an array’s items. The first array item becomes the last, and the last array item becomes the first:

See the Pen thecodelog.com - JS Arrays 2 8 by Deano (@deangilewicz) on CodePen.

The following methods manipulate the array. 1. The unshift() method adds an item to the beginning of an array:

See the Pen thecodelog.com - JS Arrays 2 9 by Deano (@deangilewicz) on CodePen.

2. The push() method adds an item to the end of an array:

See the Pen thecodelog.com - JS Arrays 2 10 by Deano (@deangilewicz) on CodePen.

3. To add an item to a specific position in an array directly bracket notation is used:

See the Pen thecodelog.com - JS Arrays 2 11 by Deano (@deangilewicz) on CodePen.

4. The shift() method removes an item from the beginning of an array (also returns that item):

See the Pen thecodelog.com - JS Arrays 2 12 by Deano (@deangilewicz) on CodePen.

5. The pop() method removes an item from the end of an array (also returns that item):

See the Pen thecodelog.com - JS Arrays 2 13 by Deano (@deangilewicz) on CodePen.

6. The splice() method changes the contents of an array by removing existing items and/or adding new items in an array (also returns item(s)):

See the Pen thecodelog.com - JS Arrays 2 14 by Deano (@deangilewicz) on CodePen.

The following methods iterate over the array and do not manipulate the array. 1. The find() method returns the found value in the array if an item in the array satisfies the provided testing function. Otherwise undefined is returned.

See the Pen thecodelog.com - JS Arrays 2 15 by Deano (@deangilewicz) on CodePen.

2. The findIndex() method returns the found index in the array of an item that satisfies the provided testing function. Otherwise -1 is returned.

See the Pen thecodelog.com - JS Arrays 2 16 by Deano (@deangilewicz) on CodePen.

3. The every() method returns true if every element in this array satisfies the provided testing function. Otherwise false is returned.

See the Pen thecodelog.com - JS Arrays 2 17 by Deano (@deangilewicz) on CodePen.

4. The some() returns true if at least one item in the array satisfies the provided testing function. Otherwise false is returned.

See the Pen thecodelog.com - JS Array 2 18 by Deano (@deangilewicz) on CodePen.

5. The filter() method creates a new array with all of the items of the array for which the provided filtering function returns true.

See the Pen thecodelog.com - JS Arrays 2 19 by Deano (@deangilewicz) on CodePen.

6. The forEach() method calls a function for each item in the array.

See the Pen thecodelog.com - JS Arrays 2 20 by Deano (@deangilewicz) on CodePen.

7. The map() methods creates a new array with the results of calling a provided function on every item in the array.

See the Pen thecodelog.com - JS Arrays 2 21 by Deano (@deangilewicz) on CodePen.

8. The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.

See the Pen thecodelog.com - JS Arrays 2 22 by Deano (@deangilewicz) on CodePen.