Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Useful_JavaScript_Array_Methods

Uploaded by

kelvinomo027
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Useful_JavaScript_Array_Methods

Uploaded by

kelvinomo027
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Most Useful JavaScript Array Methods

JavaScript provides many useful methods to work with arrays. This guide covers the most

commonly used methods, with detailed explanations and examples.

Array Creation and Access


- Array(): Creates a new array.

- []: Array literal syntax to create arrays.

- Accessing Elements: Use array[index] to access elements by index.

Adding/Removing Elements
- push(): Adds one or more elements to the end of an array and returns the new length.

- pop(): Removes the last element from an array and returns it.

- shift(): Removes the first element from an array and returns it.

- unshift(): Adds one or more elements to the beginning of an array and returns the new length.

- splice(): Adds or removes elements from an array.

- concat(): Merges two or more arrays.

Searching
- find(): Returns the first element that satisfies a condition.

- findIndex(): Returns the index of the first element that satisfies a condition.

- filter(): Creates a new array with elements that satisfy a condition.

- includes(): Checks if an array contains a specific element.

- indexOf(): Returns the index of a specified element in the array, or -1 if not found.

Iteration
- forEach(): Executes a provided function once for each array element.

- map(): Creates a new array with the results of calling a function on every element.
- reduce(): Executes a reducer function on each element to reduce it to a single value.

- reduceRight(): Same as reduce(), but processes the array from right to left.

Array Transformation
- slice(): Returns a shallow copy of a portion of an array.

- join(): Joins all elements of an array into a string.

- flat(): Flattens nested arrays into a single array.

- flatMap(): Maps each element and flattens the result into a new array.

Other Utility Methods


- some(): Tests whether at least one element satisfies a condition.

- every(): Tests whether all elements satisfy a condition.

- sort(): Sorts the elements of an array in place.

- reverse(): Reverses the order of the elements in an array.

You might also like