JavaScript Array Methods
A global object used in the creation of arrays in JavaScript is the Array object. A unique kind of variable called an array enables you to store several values in a single variable.
Method | Description |
---|---|
concat() | Returns a new array after merging two or more arrays. |
copyWithin() | Returns the result of copying a portion of an array to another position inside the same array. |
entries() | a key/value pair Array Iteration object is returned. |
every() | determines if each member in the array satisfies the requirements of the test function. |
fill() | An array's elements should have a constant value assigned to them. |
filter() | assembles all the components in a new array that pass the test in the test method. |
find() | The test method returns the value of the first member in an array that satisfies the condition. |
findIndex() | gives the test function the index of the first element in an array that passes the test. |
forEach() | calls the method just once for each element of the array. |
from() | uses an object to create an array. |
includes() | determines if a specific element is present in an array. |
indexOf() | Find an element in the array and return its initial index. |
isArray() | determines whether an array is present in the provided value. |
join() | combines all of an array's items into a string. |
keys() | returns an Array Iteration Object with the original array's keys in it. |
lastIndexOf() | Beginning at the end, search the array for an element, returning its last index. |
map() | creates a new array with the outcomes of performing a function on each member of the original array. |
pop() | returns the element that was removed from the end of an array. |
push() | returns the length of the array after adding one or more elements to the end. |
reduce() | Reduce an array's values to a single value (from left-to-right). |
reduceRight() | Reduce an array's values to a single value (from right-to-left). |
reverse() | reverses the order of an array's items. |
shift() | returns the element that was removed as the first element from an array. |
slice() | returns a new array after choosing a portion of the original array. |
some() | determines if any array element has passed the test in a testing method. |
sort() | sorts the array's component parts. |
splice() | removes or adds elements to an array. |
toString() | yields the result of converting an array to a string. |
unshift() | returns the length of the array after adding additional members to the beginning. |
values() | provides an Array Iteration Object with the values of the first array as a return value. |
constructor | |
length | sets or returns the array's element count. |
prototype | enables you to extend an Array object with new attributes and methods. |
1. JavaScript Array Concat()
The concat() function connects (concatenates) up to two arrays. A new array comprising the combined arrays is returned by the concat() function. The arrays that already exist are unaffected by the concat() technique.
2. JavaScript Array copyWithin()
The copyWithin() function moves an array element to a different location. The previous values are replaced using the copyWithin() technique. The array is not expanded by the copyWithin() function.
3. JavaScript Array entries()
Key/value pairs are returned by the entries() function as an Array Iterator object. The original array is unaltered by the entries() function.
4. JavaScript Array every()
Every() runs a function on each element of the array. If the function returns true for all items, the every() method returns true. If the function returns false for one element, the every() method returns false. For empty items, the every() method does not run the code. The original array is unchanged by the every() function.
5. JavaScript Array fill()
The fill() function inserts a value into a specific array element. The initial array is replaced using the fill() function. You can choose the start and finish positions. All components will be filled if not.
6. JavaScript Array filter()
A new array of elements that pass a test supplied by a function is created by the filter() method. For empty items, the filter() method does not run the function. The original array is unaltered by the filter() technique.
7. JavaScript Array find()
The value of the first element that passes a test is returned by the find() function. Each array element is given its own function to run by the find() method. If no items are discovered, the find() function returns undefined. For empty items, the find() method does not run the function. The original array is unaltered by the find() function.
8. JavaScript Array findIndex()
Each array element is given its own function to run via the findIndex() method. The first element to pass a test is returned by the findIndex() function as its index (position). In the event there is no match, the findIndex() function returns -1. For empty array members, the findIndex() method does not run the function. The original array is unaltered by the findIndex() function.
9. JavaScript Array forEach()
For each entry in an array, the forEach() method invokes a different function. When dealing with empty items, the forEach() function is not used.
10. JavaScript Array from()
Every object with a length property can yield an array by using the Array.from() function. Every iterable object can be converted into an array using the Array.from() function.
11. JavaScript Array includes()
In the event that an array contains the given value, the includes() function returns true. If the value cannot be found, includes() returns false. Case distinctions apply to the includes() function.
12. JavaScript Array indexOf()
The initial index (position) of a value supplied is returned by the indexOf() function. -1 is returned by the indexOf() function if the value cannot be found. The indexOf() function performs a left-to-right search beginning at a given index. The search defaults to beginning at the first element and ending at the last. Negative start values start counting with the previous element (but still searches from left to right).
13. JavaScript Array isArray()
If an object is an array, the isArray() function returns true; otherwise, it returns false.
14. JavaScript Array join()
The array from the join() function is returned as a string. The original array is unaltered by the join() technique. The divider might be anything. The comma is the standard (,).
15. JavaScript Array keys()
An Array Iterator object with an array's keys is the result of the keys() function. The initial array is unchanged by the keys() function.
16. JavaScript Array lastIndexOf()
The last index (position) of a given value is returned by the lastIndexOf() function. -1 is returned by the lastIndexOf() function if the value cannot be found. The lastIndexOf() function performs a right-to-left search beginning at a given index. The search defaults to beginning at the last element and ending at the first. Beginning with the last element, negative start values count.
17. JavaScript Array map()
For each element of an array, map() calls a function to generate a new array. For each element in an array, map() makes a single call to a function. With empty items, the function is not run by map(). The initial array is unaffected by map().
18. JavaScript Array pop()
The final member of an array is removed (popped) by the pop() function. The initial array is changed using the pop() function. The eliminated element is returned by the pop() function.
19. JavaScript Array push()
A new item is added to the end of an array using the push() function. The array's length is altered via the push() function. The new length is returned by the push() operation.
20. JavaScript Array reduce()
A reducer function is run for each element of an array using the reduce() method. The function's total result is the only value that the method returns. For empty array entries, the method does not run the function. The original array is unaltered by the reduce() technique.
21. JavaScript Array reduceRight()
For each member of the array, the reduceRight() method runs a reducer function. From right to left, the reduceRight() function operates. The function's total result is the only thing the reduceRight() method returns. When an element is empty, the reduceRight() method does not run the function.
22. JavaScript Array reverse()
The array's elements are rearranged using the reverse() technique. The initial array is overwritten by the reverse() function.
23. JavaScript Array shift()
The first element of an array is eliminated using the shift() function. The initial array is modified with the shift() technique. The shifted element is returned by the shift() function.
24. JavaScript Array slice()
The array's chosen items are returned as a new array by the slice() function. The slice() function makes choices between a specified start and a specified (not inclusive) finish. The original array is unaltered by the slice() technique.
25. JavaScript Array some()
The some() method determines which array members pass an evaluation (provided as a callback function). For each entry of the array, the some() method calls the callback function once. If the function returns true for one of the array entries, the some() method returns true (and ends). If the function returns false for each entry in the array, the some() method returns false. In the case of empty array items, the some() method does not run the function. The initial array is unchanged by the some() function.
26. JavaScript Array sort()
The array items are sorted using sort(). The initial array is replaced with sort(). The sort() function alphabetically and ascendingly organizes the elements as strings.
27. JavaScript Array splice()
The splice() function inserts and/or deletes entries from an array. The initial array is replaced with the splice() technique.
28. JavaScript Array toString()
A string containing array values separated by commas is the result of the toString() function. The original array is unaltered by the toString() function.
29. JavaScript Array unshift()
A new element is added to the beginning of an array using the unshift() function. The original array is replaced using the unshift() technique.
30. JavaScript Array valueof()
The array itself is returned by the valueOf() function. The original array is unchanged by the valueOf() function. fruits. Fruits are returned by valueOf() as well.
31. JavaScript Array Constructor
The function that built the Array prototype is returned via the constructor property.
32. JavaScript Array length
The length property provides an easy way to append a new element to an array.
33. JavaScript Array prototype
Prototype allows you to add new properties and methods to arrays.