some() method
This method checks whether at least one element of the array satisfies the conditions checked by the parameter function.
Output:
true
reduce () method
The array reduce () method in Javascript is used to reduce the array to a single value, and for the array Each value of (from left to right) and return value executes a provided function. Functions are stored in the accumulator.
Output:
3
map() method
The map() method in Javascript works by calling a specific function to create an array. This is a non-mutating method. Typically, the map() method is used to iterate over the array and call a function on each element of the array.
Output:
true
flat() method
This method creates a new array that contains multiple arrays. Basically create a simple array from an array containing multiple arrays.
Output:
11, 89, 23 ,7,98
flatMap() method
This method is used to flatten the input array elements into a new array. This method first maps each element with the help of the map function, then flattens the input array elements into a new array.
Output:
112, 52, 944
findindex() method
This method returns the first in the given array that satisfies the provided test function The index of the element. Otherwise -1 is returned.
Output:
2
find() method
This method is used to get the value of the first element in the array that satisfies the provided criteria. It checks all elements of the array, and the first element that satisfies the condition is printed.
Output:
30
fill() method
This method is used to populate the array with the given static value. The value can be used to fill the entire array, or it can be used to fill a portion of the array.
Output:
1, 87, 87 ,58
forEach() method
This method calls the provided function once for each element of the array. Provided functions can perform any type of operation on the elements of the given array.
Output:
10, 25, 50 、88
concat() method
This method is used to merge two or more arrays together . This function does not alter the original array passed as an argument.
Output:
11, 12, 13 , 14, 15, 15, 16, 17, 18, 19
include() method
This method It is used to know if a particular element is present in the array, therefore, it returns true or false, i.e., if the element exists, it returns true, otherwise it returns false.
Output:
true
reverse() method
This method is used for in-place inversion of an array. The first element of the array becomes the last element and vice versa.
function func() { //Original Array var arr = [34, 234, 567, 4]; document.write("Original array: " + arr); //Reversed array var new_arr = arr. reverse(); document.write("
Newly reversed array: "); document.write(new_arr); } func();
Output:
Original array: 34, 234, 567, 4 New reversed array: 4, 567, 234, 34
Recommended tutorial: “JS Tutorial”
The above is the detailed content of array methods commonly used in Javascript. For more, please pay attention to other related articles on 1024programmer.com!