DEV Community

Cover image for 8 JAVASCRIPT ARRAY Methods for Beginner
Kamran Ahmad
Kamran Ahmad

Posted on

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"]
Enter fullscreen mode Exit fullscreen mode
  1. 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"]
Enter fullscreen mode Exit fullscreen mode
  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"
Enter fullscreen mode Exit fullscreen mode
  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"]
Enter fullscreen mode Exit fullscreen mode
  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]
Enter fullscreen mode Exit fullscreen mode
  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"]
Enter fullscreen mode Exit fullscreen mode
  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"]
Enter fullscreen mode Exit fullscreen mode
  1. INCLUDES The includes() determines whether an array contains s specified element.
const arr = ["The", "Coding", "Master"];
arr.includes("Coding");//true

Enter fullscreen mode Exit fullscreen mode

Discussion (0)