Last Updated : 05 Aug, 2025
To help you perform common tasks efficiently, JavaScript provides a wide variety of array methods. These methods allow you to add, remove, find, and transform array elements with ease.
Javascript Arrays Methods 1. JavaScript Array lengthThe length property of an array returns the number of elements in the array. It automatically updates as elements are added or removed.
JavaScript
let a = ["HTML", "CSS", "JS", "React"];
console.log(a.length);
In this example
The toString() method converts the given value into the string with each element separated by commas.
JavaScript
let a = ["HTML", "CSS", "JS", "React"];
let s = a.toString();
console.log(s);
In this example
This join() method creates and returns a new string by concatenating all elements of an array. It uses a specified separator between each element in the resulting string.
JavaScript
let a = ["HTML", "CSS", "JS", "React"];
console.log(a.join('|'));
In this example
The delete operator is used to delete the given value which can be an object, array, or anything.
let emp = {
firstName: "Riya",
lastName: "Kaur",
salary: 40000
}
console.log(delete emp.salary);
console.log(emp);
true { firstName: 'Riya', lastName: 'Kaur' }
In this example
The concat() method is used to concatenate two or more arrays and it gives the merged array.
JavaScript
let a1 = [11, 12, 13];
let a2 = [14, 15, 16];
let a3 = [17, 18, 19];
let newArr = a1.concat(a2, a3);
console.log(newArr);
[ 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
In this example
The flat() method is used to flatten the array i.e. it merges all the given array and reduces all the nesting present in it.
JavaScript
const a1 = [['1', '2'], ['3', '4', '5',['6'], '7']];
const a2 = a1.flat(Infinity);
console.log(a2);
[ '1', '2', '3', '4', '5', '6', '7' ]
In this example
The push() method is used to add an element at the end of an Array. As arrays in JavaScript are mutable objects, we can easily add or remove elements from the Array.
JavaScript
let a = [10, 20, 30, 40, 50];
a.push(60);
a.push(70, 80, 90);
console.log(a);
[ 10, 20, 30, 40, 50, 60, 70, 80, 90 ]8. JavaScript Array.unshift() Method
The unshift() method is used to add elements to the front of an Array.
JavaScript
let a = [20, 30, 40];
a.unshift(10, 20);
console.log(a);
[ 10, 20, 20, 30, 40 ]9. JavaScript Array.pop() Method
The pop() method is used to remove elements from the end of an array.
JavaScript
let a = [20, 30, 40, 50];
a.pop();
console.log(a);
10. JavaScript Array.shift() Method
The shift() method is used to remove elements from the beginning of an array
JavaScript
let a = [20, 30, 40, 50];
a.shift();
console.log(a);
11. JavaScript Array.splice() Method
The splice() method is used to Insert and Remove elements in between the Array.
JavaScript
let a = [20, 30, 40, 50];
a.splice(1, 3);
a.splice(1, 0, 3, 4, 5);
console.log(a);
The slice() method returns a new array containing a portion of the original array, based on the start and end index provided as arguments
JavaScript
const a = [1, 2, 3, 4, 5];
const res = a.slice(1, 4);
console.log(res);
console.log(a)
[ 2, 3, 4 ] [ 1, 2, 3, 4, 5 ]
In this example
The some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument function.
JavaScript
const a = [1, 2, 3, 4, 5];
let res = a.some((val) => val > 4);
console.log(res);
In this example
The map() method creates an array by calling a specific function on each element present in the parent array. It is a non-mutating method.
JavaScript
let a = [4, 9, 16, 25];
let sub = a.map(geeks);
function geeks() {
return a.map(Math.sqrt);
}
console.log(sub);
[ [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ] ]
In this example
The filter() method in JavaScript creates a new array with all elements that pass the test implemented by the provided function. It does not modify the original array.
JavaScript
let a1 = [1, 2, 3, 4, 5]
let a2 = a1.filter((num) => num > 1)
console.log(a2)
In this example
The reduce() method is used to reduce the array to a single value and executes a provided function for each value of the array (from left to right) and the return value of the function is stored in an accumulator.
JavaScript
let a = [88, 50, 25, 10];
let sub = a.reduce(geeks);
function geeks(tot, num) {
return tot - num;
}
console.log(sub);
In this example
The reverse() method is used to reverse the order of elements in an array. It modifies the array in place and returns a reference to the same array with the reversed order.
JavaScript
let a = [1, 2, 3, 4, 5];
a.reverse();
console.log(a);
In this example
The values() method returns a new Array Iterator object that contains the values for each index in the array.
JavaScript
const a = ["Apple", "Banana", "Cherry"];
const res = a.values();
for (const value of res) {
console.log(value);
}
Apple Banana Cherry
In this example
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4