0% found this document useful (0 votes)
4 views11 pages

The Mega Js Cheat-sheet, Part-1

This document is a comprehensive cheat-sheet covering various array methods in JavaScript, including adding/removing elements, finding elements, creating new arrays, transforming arrays, iterating, reducing, converting to strings, copying, and checking. Each method is briefly described with its functionality and return values. The document also hints at future topics for additional cheat-sheets, such as string methods and ES6 features.

Uploaded by

aichnil05
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)
4 views11 pages

The Mega Js Cheat-sheet, Part-1

This document is a comprehensive cheat-sheet covering various array methods in JavaScript, including adding/removing elements, finding elements, creating new arrays, transforming arrays, iterating, reducing, converting to strings, copying, and checking. Each method is briefly described with its functionality and return values. The document also hints at future topics for additional cheat-sheets, such as string methods and ES6 features.

Uploaded by

aichnil05
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
You are on page 1/ 11

THE MEGA

CHEAT-SHEET
PART - 1

@frontend_in_depth
In this post, we’ll cover all the
array methods in JavaScript.
1. Adding/Removing Elements

push(elementl, .., elementN):


Adds to end, returns new length

pop():
Removes from end, returns removed element

unshift(elementi, ., elementN):
Adds to start, returns new length

shift():
Removes from start, returns removed element

splice(start, deleteCount, iteml,.., itemN():


Changes contents by removing/replacing
elements
2. Finding Elements

indexOf(element, fromindex):
Returns first index of element, or -l

lastindexof (element, fromindex):


Returns last index of element, or -1

find (callback):
Returns first element that satisfies condition

findindex(calback):
Returns index of first element satisfying
condition

includes(element, fromlndex): Returns true if


array includes element

findLast(callback): Returns last element that


satisfies condition

findLastlindex(callback): Returns index of last


elenment satisfying condition
3. Creating New Arrays

slice(start, end):
Returns shallow copy of portion of array

concat(arrayl,..,.arrayN):
Merges arrays, returns new array

map(calback):
Creates new array with results of calback

filter(callback):
Creates new array with elements passing test

flat(depth):
Creates new array with sub-array elements
concatenated

flatMap(callback):
Maps each element, then flattens result

Array.from(arrayLike, mapFn, thisArg):


Creates new array from array-like object

Array.of (elementl, .., elementN):


Creates array with variable number of arguments
4. Transforming Arrays

sort(compareFunction):
Sorts elements in place

reverse():
Reverses order of elements in place

fill(value, start, end):


Fills array with static value

copyWithin (target, start, end): Copies part of array


to another location in same array

toSorted (compareFunction):
Returns a new sorted array

toReversed ():
Returns a new reversed array

with(index, value): Returns new array with element at


index replaced

toSpliced (start, deleteCount, iteml, ., itemN): Returns


a new array with splice applied
5. Iterating

forEach(callback):
Executes callback for each element

every(calback):
Tests if all elements pass condition

some(calback):
Tests if at least one element passes condition

entries():
Returns new Array Iterator with keylvalue pairs

(keys):
Returns new Array Iterator with array keys

values():
Returns new Array Iterator with array values

[Symbol.iterator]():
Returns new Array Iterator
6. Reducing

reduce(callback, initialValue):
Reduces to single value (left-to-right)

reduceRight (calback, initialValue):


Reduces to single value (right-to-left)

7. Converting to String

join(separator):
Joins all elements into a string

tostring():
Returns a string representing the array

toLocaleString ():
Returns a localized string representing the
array
8. Copying

Array.from(arrayLike, mapFn, thisArg):


Creates new array from array-like object

9. Creating

Array.of (elementi, .., elementN): Creates


array with variable number of arguments

10. Checking

Array.isArray (obj):
Returns true if obj is an array
11. Other

length:
Property that sets or returns the number of
elements

at(index):
Returns the element at the specified index

group(calback):
Groups elements based on callback result (not
widely supported yet)

groupTOMap (calback):
Groups elements into a Map based on callback
result (not widely supported yet)
WHAT NEXT?
1️⃣ String Methods
2️⃣ Object Methods
3️⃣ ES6 Features
4️⃣ DOM Cheat Sheet
Comment below and let me know
which topic you'd like the next
cheatsheet on!

You might also like