DEV Community

vishwa v
vishwa v

Posted on • Edited on

method-5

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")
Enter fullscreen mode Exit fullscreen mode

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];
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)