An array is a special variable in all the languages that are used to store different elements. JavaScript array contains some built-in properties that every JavaScript developer should know how to use and when or where to use them. We can use them to add, remove, iterate, or manipulate data as per our requirements.

Basic JavaScript Array Methods:
There are some Basic JavaScript array methods that every developer should know are:
This method checks whether at least one of the elements of the array satisfies the condition checked by the argument function.
Example:
Here is an example of the basic use of the Array some() method.
Javascript
function isGreaterThan5(element, index, array) {
return element > 5;
}
function func() {
let array = [2, 5, 8, 1, 4];
let value = array.some(isGreaterThan5);
console.log(value);
}
func();
|
The array reduce() method in JavaScript 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.
Example:
Here is an example of the basic use of the Array reduce() method.
javascript
let numbers = [88, 50, 25, 10];
let sub = numbers.reduce(geeks);
function geeks(total, num) {
return total - num;
}
console.log(sub);
|
The map() method in JavaScript creates an array by calling a specific function on each element present in the parent array. It is a non-mutating method. Generally, the map() method is used to iterate over an array and call the function on every element of an array.
Example:
Here is an example of the basic use of the Array map() method.
javascript
let numbers = [4, 9, 16, 25];
let sub = numbers.map(geeks);
function geeks() {
return numbers.map(Math.sqrt);
}
console.log(sub);
|
Output
[ [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ], [ 2, 3, 4, 5 ] ]
This method checks whether all the elements of the array satisfy the given condition or not that is provided by a function passed to it as the argument.
Example:
Here is an example of the basic use of the Array every() method.
javascript
function ispositive(element, index, array) {
return element > 0;
}
function func() {
let arr = [11, 89, 23, 7, 98];
let value = arr.every(ispositive);
console.log(value);
}
func();
|
This method creates a new array that contains more than arrays. Basically creates a simple array from an array that contains multiple arrays.
Example:
Here is an example of the basic use of the Array flat() method.
javascript
let arr = [[11, 89], [23, 7], 98];
let geeks = arr.flat();
console.log(geeks);
|
Output
[ 11, 89, 23, 7, 98 ]
This method is used to flatten the input array element into a new array. This method first of all map every element with the help of a mapping function, then flattens the input array element into a new array.
Example:
Here is an example of the basic use of the Array flatMap() method.
javascript
const myAwesomeArray = [
[1], [2], [3], [4], [5]
];
let geeks = myAwesomeArray.flatMap(
(arr) => arr * 10
);
console.log(geeks);
|
Output
[ 10, 20, 30, 40, 50 ]
This method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument function.
Example:
Here is an example of the basic use of the Array filter() Method.
javascript
function isPositive(value) {
return value > 0;
}
function func() {
let filtered = [112, 52, 0, -1, 944]
.filter(isPositive);
console.log(filtered);
}
func();
|
This method returns the index of the first element in a given array that satisfies the provided testing function. Otherwise, -1 is returned.
Example:
Here is an example of the basic use of the Array.findindex() method.
javascript
let array = [10, 20, 30, 110, 60];
function finding_index(element) {
return element > 25;
}
console.log(array
.findIndex(finding_index)
);
|
This method is used to get the value of the first element in the array that satisfies the provided condition. It checks all the elements of the array and whichever the first element satisfies the condition is going to print.
Example:
Here is an example of the basic use of the Array find() method.
javascript
let array = [10, 20, 30, 40, 50];
let found = array.find( function (element) {
return element > 20;
});
console.log(found);
|
This method is used to fill the array with a given static value. The value can be used to fill the entire array or it can be used to fill a part of the array.
Example:
Here is an example of the basic use of the Array fill() Method.
javascript
let arr = [1, 23, 46, 58];
arr.fill(87, 1, 3);
console.log(arr);
|
This method calls the provided function once for each element of the array. The provided function may perform any kind of operation on the elements of the given array.
Example:
Here is an example of the basic use of the Array forEach() Method.
javascript
const items = [1, 29, 47];
const copy = [];
items.forEach( function (item) {
copy.push(item * item);
});
console.log(copy);
|
This method is used to sort the array. An array can be of any type i.e. string, numbers, characters, etc.
Example:
Here is an example of the basic use of the Array sort() Method:
javascript
let numbers = [88, 50, 25, 10];
let sub = numbers.sort(geeks);
function geeks(a, b) {
return a - b;
}
console.log(sub);
|
Output
[ 10, 25, 50, 88 ]
This method is used to merge two or more arrays together. This function does not alter the original arrays passed as arguments.
Example:
Here is an example of the basic use of the Array concat() Method.
javascript
let num1 = [11, 12, 13],
num2 = [14, 15, 16],
num3 = [17, 18, 19];
console.log(num1.concat(num2, num3));
|
Output
[
11, 12, 13, 14, 15,
16, 17, 18, 19
]
This method is used to know whether a particular element is present in the array or not and accordingly, it returns true or false i.e, if the element is present, then it returns true otherwise false
Example:
Here is an example of the basic use of the Array includes() Method.
javascript
let A = [1, 2, 3, 4, 5];
let a = A.includes(2);
console.log(a);
|
This method is used for in-place reversal of the array. The first element of the array becomes the last element and vice versa.
Example:
Here is an example of the basic use of the Array reverse() method
javascript
let arr = [34, 234, 567, 4];
console.log( "Original array: " + arr);
let new_arr = arr.reverse();
console.log( "Newly reversed array: " + new_arr);
|
Output
Original array: 34,234,567,4
Newly reversed array: 4,567,234,34
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
11 Jul, 2023
Like Article
Save Article