JavaScript Array keys()
The Array.keys() method returns an Array Iterator object with the keys of an array.
JavaScript Array entries()
The entries() method returns an Array Iterator object with key/value pairs:
[0, "Banana"]
[1, "Orange"]
[2, "Apple"]
[3, "Mango"]
The entries() method does not change the original array.
JavaScript Array with() Method
ES2023 added the Array with() method as a safe way to update elements in an array without altering the original array.
const months = ["Januar", "Februar", "Mar", "April"];
const myMonths = months.with(2, "March")
JavaScript Array Spread (...)
The ... operator expands an array into individual elements.
This can be used join arrays:
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = [...arr1, ...arr2];
JavaScript Array Rest (...)
The rest operator (...) allows us to destruct an array and collect the leftovers:
Examples
let a, rest;
const arr1 = [1,2,3,4,5,6,7,8];
[a, ...rest] = arr1;
Top comments (0)