ARRAY4
ARRAY4
Returns the element at the specified let arr = [10, 20, 30]; let
at(index) element = 30
index. Negative integers count back element = arr.at(-1);
1 from the last item in the array.
let arr1 = [1, 2]; let arr2 = [3,
concat(...items) Merges two or more arrays and 4]; let result = result = [1, 2, 3, 4]
2 returns a new array. arr1.concat(arr2);
let arr = [1, 2, 3]; let constructor =
constructor Refers to the function that created the
constructor = arr.constructor; Array
3 array's prototype, which is Array.
Copies a part of the array to another
copyWithin(target, let arr = [1, 2, 3, 4, 5];
location in the same array without arr = [4, 2, 3, 4, 5]
start, end) arr.copyWithin(0, 3, 4);
4 modifying its length.
Returns a new array iterator object let arr = ['a', 'b', 'c']; let iterator
[0, 'a'] [1, 'b'] [2,
entries() that contains the key/value pairs for = arr.entries(); for (let e of
'c']
iterator) console.log(e);
5 each index in the array.
Tests whether all elements in the array
every(callback, let arr = [1, 2, 3]; let result =
pass the test implemented by the result = true
thisArg) arr.every(x => x > 0);
6 provided function.
Fills all the elements of an array from a
let arr = [1, 2, 3, 4]; arr.fill(0, 1,
fill(value, start, end) start index to an end index with a arr = [1, 0, 0, 4]
3);
7 static value.
filter(callback, Creates a new array with all elements let arr = [1, 2, 3, 4]; let result =
result = [3, 4]
thisArg) that pass the test implemented by the arr.filter(x => x > 2);
8 provided function.
Returns the value of the first element
find(callback, let arr = [1, 2, 3, 4]; let result =
in the array that satisfies the provided result = 3
thisArg) arr.find(x => x > 2);
9 testing function.
Returns the index of the first element
findIndex(callback, let arr = [1, 2, 3, 4]; let index =
in the array that satisfies the provided index = 2
thisArg) arr.findIndex(x => x > 2);
10 testing function.
Returns the value of the last element
findLast(callback, let arr = [1, 2, 3, 4]; let result =
in the array that satisfies the provided result = 4
thisArg) arr.findLast(x => x > 2);
11 testing function.
Returns the index of the last element
findLastIndex(callba let arr = [1, 2, 3, 4]; let index =
in the array that satisfies the provided index = 3
ck, thisArg) arr.findLastIndex(x => x > 2);
12 testing function.
Creates a new array with all sub-array let arr = [1, [2, [3, [4]]]]; let result = [1, 2, 3,
flat(depth)
elements concatenated into it result = arr.flat(2); [4]]
13 recursively up to the specified depth.
Maps each element using a mapping
flatMap(callback, let arr = [1, 2, 3]; let result = result = [1, 2, 2, 4,
function, then flattens the result into a
thisArg) arr.flatMap(x => [x, x * 2]); 3, 6]
14 new array.
forEach(callback, Executes a provided function once for let arr = [1, 2, 3]; arr.forEach(x 2 4 6
thisArg) => console.log(x * 2));
15 each array element.
includes(valueToFin let arr = [1, 2, 3]; let result =
Determines whether an array includes result = true
d, fromIndex) arr.includes(2);
16 a certain value among its entries.
some(callback, Tests whether at least one element in let arr = [1, 2, 3]; let result =
result = true
thisArg) the array passes the test implemented arr.some(x => x > 2);
29 by the provided function.
sort(compareFuncti Sorts the elements of an array in place
let arr = [3, 1, 2]; arr.sort(); arr = [1, 2, 3]
30 on) and returns the sorted array.
Changes the contents of an array by
splice(start,
removing or replacing existing let arr = [1, 2, 3, 4];
deleteCount, arr = [1, 5, 6, 4]
elements and/or adding new elements arr.splice(1, 2, 5, 6);
...items)
31 in place.
Returns a string representing the str =
toLocaleString(local let arr = [1, 'a', new Date()]; let
elements of the array using their '1,a,7/16/2024,
es, options) str = arr.toLocaleString();
32 toLocaleString methods. 12:00:00 AM'
Similar to reverse(), but returns a new
let arr = [1, 2, 3]; let result =
toReversed() array with the elements in reversed result = [3, 2, 1]
arr.toReversed();
33 order.
toSorted(compareF Similar to sort(), but returns a new let arr = [3, 1, 2]; let result =
result = [1, 2, 3]
34 unction) array with the elements sorted. arr.toSorted();
toSpliced(start,
let arr = [1, 2, 3, 4]; let result =
deleteCount, Similar to splice(), but returns a new result = [1, 5, 6, 4]
arr.toSpliced(1, 2, 5, 6);
35 ...items) array with the specified modifications.
Returns a string representing the let arr = [1, 2, 3]; let str =
toString() str = '1,2,3'
36 specified array and its elements. arr.toString();
Adds one or more elements to the
let arr = [2, 3]; let length = length = 4; arr = [0,
unshift(...items) front of an array and returns the new
arr.unshift(0, 1); 1, 2, 3]
37 length of the array.
Returns a new array iterator object let arr = ['a', 'b', 'c']; let iterator
values() that contains the values for each index = arr.values(); for (let value of 'a' 'b' 'c'
iterator) console.log(value);
38 in the array.
Creates a new array with the specified
let arr = [1, 2, 3]; let result =
with(index, value) element replaced by a new value at a result = [1, 4, 3]
arr.with(1, 4);
39 given index.