Lecture JS arrays
Lecture JS arrays
JS Arrays
The concat() method does not change the existing arrays, but returns a new
array, containing the values of the joined arrays.
Array1.concat(Array2)
const item1 =
[“Apple",“Mango",“Orange"];
const item2 =
Example [“Banana",“Grapes",“PineApple"];
console.log(item1.concat(item2))
copyWithin() function
console.log(array1.fill(0, 2, 3));
Example
console.log(array1.fill(0));
Example
console.log(array1.fill(7,2));
The filter() method creates an array
filled with all array elements that pass a
test
console.log(result);
find() function
• The find() method returns the value of the array element
that passes a test.
• The method executes the function once for each element
present in the array:
console.log(found);
map() function
• The map() method creates a new array with the results of calling a function
for every array element.
• The map() method calls the provided function once for each element in an
array, in order.
• map() does not execute the function for empty elements.
• map() does not change the original array.
Example
The reduce() method executes a reducer function for each value of an array.
reduce() does not execute the function for empty array elements.
console.log(animals.slice(2, 4));
console.log(animals.slice(-2));
console.log(animals.slice(2, -1));
pop() function
animals.unshift(‘FirstAnimal’);
console.log(animals);
flat() method that creates a new array with
all the elements of the subarrays
concatenated to it recursively up to a
specified depth.