JAVASCRIPT ARRAY METHODS BASIC LEARN

    Let’s talk about JavaScript Array.
  1. PUSH Method use in JavaScript Array

The push() method adds new elements to the end of the array, and returns the new length.

const = arr = ["I" , "Am"];
arr.push("Developer");

//Output
['I', 'Am', 'Developer' ]

2. SLICE Method use in JavaScript Array

The slice() method selects a part of an array, and return the new array.

const arr = ["I" , "Am" , "Developer"];
arr.slice(1, 2);
//Output
['Am']

3. TOSTRING Method use in JavaScript Array

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

const arr = ["I" , "Am" , "Developer"];
arr.toString();

//Output

"I , Am , Developer"

4. SHIFT Method use in JavaScript Array.

The shift() method removes the first element of an array, and return that element.

const arr = ["I" , "Am" , "Developer"];
arr.shift();

//Output

[ 'Am', 'Developer' ]

5. MAP Method use in JavaScript Array.

The map() method creates a new array with the results of coding a function for every array element.

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

// OutPut
[ 2, 8, 18, 32 ]

6. POP Method use in JavaScript.

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

const arr = ["I" , "Am" , "Developer"];
arr.pop();

//Output

['I' , 'am']

7. FILTER Method use in JavaScript.

The filter() method creates an array filled with all array elements that pass a test (Provided as a function)

const arr_filter = ["I" , "Am" , "Developer"];

 var filter = arr_filter.filter(word => word.length > 3);
// Output 
["Am" , "Developer"]; 

8. INCLUDES Method use in JavaScript.

The includes() method determines whether an array contains a specific element.

const arr = ["I" , "Am" , "Developer"];
arr.includes("Am");
// Output
true

Share This Article