Lists of Top 10 JavaScript array methods a beginner Js developer should know

Nusrat Jahan
Webtips
Published in
3 min readAug 18, 2020

--

Lists of Top 10 JavaScript array methods all should know
Photo by 🇨🇭 Claudio Schwarz | @purzlbaum on Unsplash

1. Push

arr.push(..element) adds a new element to the end of an array and returns the new length of the array. arr.push() method mutates the original array.

arrName.push(element1,element2,…)

The call arr.push(...) is equal to arr[arr.length] = ...

2. Pop

arr.pop() method removes an element from the end of an array and returns the removed array. This method also changes the original array and it’s length.

arrayName.pop()

3. Shift

arr.shift() method removes the first element from an array and and returns the extracted element. This method is also changes the length of the original array.

arrName.shift()

4. Unshift

arr.unshift(elements) method adds one or more element at the beginning of an array and returns the new length of the array.

Methods push and unshift can add multiple elements at once

arrName.unshift(item1, item2,….)

5. Splice

arr.splice() method change the original array by inserting, removing, and replacing elements.

//Syntex
array.splice(start[,deleteCount[, item1[, item2[, ...]]]])
Starting from the index 0 it removed 1 element.
remove and replace

6. Slice

arr.slice() method selects a portion of an array and returns a new array copying to it all items from index start to end. The original array does not change.

returns a shallow copy of a portion of an array.

7. Includes

array.includes(item, index) method looks for item starting from index given and returns true if found otherwise returns false.

return value: true/false.

8. forEach (Iterate)

The forEach() method executes a provided function once for each array element.

9. Join

arr.join() method creates a string of array items by concatenating all the elements of an array. They are separated by commas or any other given separator (/, — , +, ).

return value: string.

10. toString

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

return a string value.

--

--

Nusrat Jahan
Webtips

FrontEnd Web Developer | B.Sc in Info. & Comm. Engg.