0% found this document useful (0 votes)
9 views5 pages

JavaScript Array Methods - Cheatsheet

This document is a comprehensive cheatsheet for JavaScript array methods, covering creation, access, modification, searching, sorting, concatenation, transformation, testing, iteration, conversion, copying, deletion, and unique values. It provides syntax examples for each method and outlines various operations such as filling, chunking, and stack operations. The document serves as a quick reference for developers working with arrays in JavaScript.

Uploaded by

mir805228
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

JavaScript Array Methods - Cheatsheet

This document is a comprehensive cheatsheet for JavaScript array methods, covering creation, access, modification, searching, sorting, concatenation, transformation, testing, iteration, conversion, copying, deletion, and unique values. It provides syntax examples for each method and outlines various operations such as filling, chunking, and stack operations. The document serves as a quick reference for developers working with arrays in JavaScript.

Uploaded by

mir805228
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# [ JavaScript Array Methods ] [ cheatsheet ]

Creation and Initialization

○ let arr = [];: Create an empty array.


○ let arr = [element1, element2, ...];: Create an array with
elements.

Access and Slicing

○ arr[index]: Access an element by index.


○ [Link](start, end): Extracts a section of the array and returns
a new array.
○ [Link](start): Extracts elements from the start index to the end
of the array.
○ [Link](-n): Extracts the last n elements of the array.

Modification and Assignment

○ arr[index] = value;: Assign a new value to an element.


○ [Link](element): Add an element to the end.
○ [Link](element): Add an element to the beginning.
○ [Link](): Remove and return the last element.
○ [Link](): Remove and return the first element.
○ [Link](start, deleteCount, item1, item2, ...): Change the
contents of an array by removing or replacing existing elements.

Searching and Counting

○ [Link](element): Check if an element is in the array.


○ [Link](element): Return the index of the first occurrence of an
element.
○ [Link](element): Return the index of the last occurrence
of an element.
○ [Link](callback): Create a new array with elements that pass
the test implemented by the provided function.

Sorting and Reversing

○ [Link](compareFunction): Sort the elements of an array in place.


○ [Link](): Reverse the order of the elements in the array.

Concatenation and Joining

By: Waleed Mousa


○ [Link](array1, array2, ...): Merge two or more arrays.
○ [Link](separator): Combine all array elements into a single
string.

Transformation

○ [Link](callback): Create a new array with the results of calling a


provided function on every element.
○ [Link](callback, initialValue): Apply a function against an
accumulator and each element in the array to reduce it to a single
value.
○ [Link](callback): Map and then flatten the result by one-level
depth.

Testing and Comparison

○ [Link](callback): Check if all elements pass a test.


○ [Link](callback): Check if at least one element passes a test.
○ [Link](callback): Return the first element that satisfies the
provided testing function.
○ [Link](callback): Return the index of the first element that
satisfies the provided testing function.

Iteration

○ [Link](callback): Execute a provided function once for each


array element.
○ for...of: Loop through the values of an iterable object (arrays,
strings, etc.).

Conversion

○ [Link](arrayLike, mapFn, thisArg): Create a new, shallow-copied


Array instance from an array-like or iterable object.
○ [Link](obj): Check if an object is an array.

Copy and Cloning

○ [Link](): Make a shallow copy of the array.


○ [...arr]: Another way to make a shallow copy.

Deletion

○ [Link] = 0;: Clear the entire array.


○ [Link](0, [Link]);: Remove all elements from the array.

By: Waleed Mousa


Concatenation and Repetition

○ [Link](arr2): Concatenate two arrays.


○ [Link](...arr2): Concatenate multiple arrays.
○ [Link](value, start, end): Fill the elements of an array with a
static value from the start index to the end index.

Flattening

○ [].concat(...arr): Flatten a nested array into a single array.

Unique Values

○ [...new Set(arr)]: Remove duplicates and get unique values from an


array.

Convert to String

○ [Link](): Convert an array to a string.

Length and Size

○ [Link]: Get the number of elements in the array.


○ [Link]({ length: n }, (v, i) => i): Generate an array of
numbers from 0 to n-1.

Joining Elements

○ [Link](separator): Join all elements of the array into a string.

Spreading

○ [...arr]: Spread syntax for creating a new array.

Filling

○ [Link](value, start, end): Fill the elements of an array with a


static value from the start index to the end index.

Chunking
○ [Link]({ length: [Link]([Link] / chunkSize) }, (_, index)
=> [Link](index * chunkSize, index * chunkSize + chunkSize)):
Split an array into chunks of a specific size.

Unique Values

○ [Link](new Set(arr)): Remove duplicates and get unique values


from an array.
By: Waleed Mousa
Check Array

○ [Link](arr): Check if a variable is an array.

Index Operations

○ [Link](element): Find the index of a specific element.


○ [Link](element): Find the last index of a specific element.
○ [Link](callback): Find the index of the first element that
satisfies a condition.
○ [Link](callback): Find the index of the last element that
satisfies a condition.
○ [Link](callback): Find the index of the first element that
satisfies a condition.
○ [Link](callback): Find the index of the last element that
satisfies a condition.

Sorting

○ [Link](): Sort elements in an array.


○ [Link](compareFunction): Sort elements using a custom compare
function.

Checking Elements

○ [Link](element): Check if an array contains a specific


element.
○ [Link](callback): Check if all elements satisfy a condition.
○ [Link](callback): Check if at least one element satisfies a
condition.

Transforming Elements

○ [Link](callback): Map each element to a new value.


○ [Link](callback): Filter elements based on a condition.
○ [Link](callback, initialValue): Reduce elements to a single
value.

Iteration

○ [Link](callback): Iterate over array elements.

Copying and Cloning

○ [Link](): Create a shallow copy of the array.

By: Waleed Mousa


○ [...arr]: Another method to create a shallow copy.
○ [Link](arr): Create a shallow copy using [Link]().

Concatenation and Joining

○ [Link](array1, array2, ...): Concatenate arrays.


○ [Link](separator): Join array elements into a string.

Conversion

○ [Link](iterable): Convert an iterable (like Set, Map, etc.) to


an array.
○ [Link](...elements): Create an array from a list of elements.

Fill and Update

○ [Link](value, start, end): Fill array elements with a static


value.
○ [Link](target, start, end): Copy array elements within the
array, overwriting the existing ones.

Find Operations

○ [Link](callback): Find the first element that satisfies a


condition.
○ [Link](callback): Find the index of the first element that
satisfies a condition.

Chunking
○ [Link]({ length: [Link]([Link] / chunkSize) }, (_, index)
=> [Link](index * chunkSize, index * chunkSize + chunkSize)):
Split an array into chunks of a specific size.

Stack Operations

○ [Link](element): Add an element to the end of the array (stack).


○ [Link](): Remove and return the last element from the end of the
array (stack).

By: Waleed Mousa

You might also like