Answers for "destructure array javascript"

3

destructuring arrays with rest operator

// Rest operator on Arrays;
// It's usually shown as ...rest
// but you can name this what you like
// Think of it as "get the ...rest of the array"
const [q, r, ...callThisAnythingYouWant] = [1, 2, 3, 4, 5, 6, 7, 8];

console.log(q, r); // 1 2
console.log(callThisAnythingYouWant); // [ 3, 4, 5, 6, 7, 8 ]
Posted by: Guest on March-05-2020
5

array destructuring

//Without destructuring

const myArray = ["a", "b", "c"];

const x = myArray[0];
const y = myArray[1];

console.log(x, y); // "a" "b"

//With destructuring

const myArray = ["a", "b", "c"];

const [x, y] = myArray; // That's it !

console.log(x, y); // "a" "b"
Posted by: Guest on January-18-2021
1

Javascript array destructuring

let [a, b] = [9, 5]
[b, a] = [a, b]
console.log(a, b);
//Expected output: 5,9
Posted by: Guest on September-11-2021
1

How to Destructuring Array in Javascript?

//destructuring array 
const alphabet = ['a', 'b', 'c', 'b', 'e'];
const [a, b] = alphabet;
console.log(a, b);
//Expected output: a b
Posted by: Guest on September-03-2021
5

destructure array javascript

var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
Posted by: Guest on May-31-2020
1

destructuring Array in JavaScript

let [greeting = "hi",name = "Sarah"] = ["hello"];

console.log(greeting);//"Hello"
console.log(name);//"Sarah"
Posted by: Guest on May-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language