DEV Community

Kate Galushko
Kate Galushko

Posted on

Most Common Array Methods JavaScript in 2023

Let’s talk about JavaScript Array. If you are looking for a job or learning JavaScript these methods might be very helpful during coding interviews. Here you can find how to prepare for a coding interview in one week.

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' ]
Enter fullscreen mode Exit fullscreen mode

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']
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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' ]
Enter fullscreen mode Exit fullscreen mode

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 ]
Enter fullscreen mode Exit fullscreen mode

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']
Enter fullscreen mode Exit fullscreen mode

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"] 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I would also recommend my article about "Most Commonly Used JavaScript Methods in 2023" and my list of great programming and coding books.

If you like this article please Comment or Like :)

Top comments (0)