The Mega Js Cheat-sheet, Part-1
The Mega Js Cheat-sheet, Part-1
CHEAT-SHEET
PART - 1
@frontend_in_depth
In this post, we’ll cover all the
array methods in JavaScript.
1. Adding/Removing Elements
pop():
Removes from end, returns removed element
unshift(elementi, ., elementN):
Adds to start, returns new length
shift():
Removes from start, returns removed element
indexOf(element, fromindex):
Returns first index of element, or -l
find (callback):
Returns first element that satisfies condition
findindex(calback):
Returns index of first element satisfying
condition
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
sort(compareFunction):
Sorts elements in place
reverse():
Reverses order of elements in place
toSorted (compareFunction):
Returns a new sorted array
toReversed ():
Returns a new reversed array
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)
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
9. Creating
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!