8 JAVASCRIPT ARRAY Methods for Beginner

  1. PUSH The push() method adds new elements to the end of an array and returns the new length.
const arr = ["The", "coding"];
arr.push("Master");
//["The", "Coding", "Master"]

2. SLICE The slice() method selects a part of an array and returns the new array.

const arr = ["The", "Coding", "Master"];
arr.slice(1,2);
//["Coding", "Master"]

3. TOSTRING

The toString() method converts an array to a string and returns the result.

const arr = ["The", "Coding", "Master"];
arr.tostring();
//"The, Coding, Master"

4. SHIFT The shift() method removes the first element of the array and returns that element.

const arr = ["The", "Coding", "Master"];
arr.shift();
//["Coding", "Master"]

5. MAP The map() method creates a new array with the result of calling a function of every array element.

const arr = [1, 4, 9, 16];
arr.map( x => x * 2);
//[2, 8, 16, 32]

6. POP The pop() method removes the last element of an array and returns that element.

const arr = ["The", "Coding", "Master"];
arr.pop();
///["The", "Coding"]

7. FILTER The filter() method creates an array filled with all array elements that pass a test (provided as a function).

const arr = ["The", "Coding", "Master"];
arr.filter(word =>word.length > 3);
//["Coding", "Master"]

8. INCLUDES The includes() determines whether an array contains s specified element.

const arr = ["The", "Coding", "Master"];
arr.includes("Coding");
//true

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store