8 JAVASCRIPT ARRAY Methods for Beginner

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"]
  1. TOSTRING The toString() method converts an array to a string and returns the result.
const arr = ["The", "Coding", "Master"];
arr.tostring();//"The, Coding, Master"
  1. SHIFT The shift() method removes the first element of the array and returns that element.
const arr = ["The", "Coding", "Master"];
arr.shift();//["Coding", "Master"]
  1. 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]
  1. POP The pop() method removes the last element of an array and returns that element.
const arr = ["The", "Coding", "Master"];
arr.pop();///["The", "Coding"]
  1. 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"]
  1. INCLUDES The includes() determines whether an array contains s specified element.
const arr = ["The", "Coding", "Master"];
arr.includes("Coding");//true

Did you find this article valuable?

Support Kamran Ahmad by becoming a sponsor. Any amount is appreciated!