JavaScript Array Functions Cheat Sheet Part 1
concat()
concat() merge two or more arrays
Syntax
const new_array = old_array
.concat([value1[, value2[, ...[, valueN]]]])
Example
[10, 20].concat([50], [70, 90])
// [ 10, 20, 50, 70, 90 ]
copyWithin()
copyWithin() copies part of array to another location
Syntax
arr.copyWithin(target[, start[, end]])
Example
[ 10, 20, 30, 40, 50 ].copyWithin(0,2)
// [ 30, 40, 50, 40, 50 ]
entries()
Array Iterator with key/value pairs for each index
Syntax
arr.entries()
Example
['a', 'b', 'c']
.entries() // Array Iterator { }
.next() // { value: (2) […], done: false }
.value // Array [ 0, "a" ]
every()
every() tests if all elements in the array pass the test
Syntax
arr.every(callback(element[, index[, array]])[, thisArg])
Example
[1, 30, 40].every(val => val > 0) // true
fill()
fill() changes elements in an array to a static value
Syntax
arr.fill(value[, start[, end]])
Example
[1, 2, 3, 4].fill('x', 1, 3)
// [ 1, "x", "x", 4 ]
filter()
filter() creates a new array with elements that pass the test
Syntax
let newArray = arr
.filter(callback(
element[, index, [array]]
)[, thisArg])
Example
[1, 10, 5, 6].filter(val => val > 5)
// [ 10, 6 ]
Thanks for reading... 👏👏👏
0 Comments
If you have any question please ask?