Lists of Top 10 JavaScript array methods a beginner Js developer should know
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.
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.
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.
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.
5. Splice
arr.splice() method change the original array by inserting, removing, and replacing elements.
//Syntex
array.splice(start[,deleteCount[, item1[, item2[, ...]]]])
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.
7. Includes
array.includes(item, index) method looks for item starting from index given and returns true if found otherwise returns 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 (/, — , +, ).
10. toString
toString() method converts an array to a string and returns string as a result.