Is there a way I can restructure part of a destructuring assignment?

Asad Saeeduddin

Let's say I have an array of arrays, like so:

var arrs = [
    [1, "foo", "bar", "baz"],
    [2, "bar", "baz", "qux"],
    [3, "baz", "qux", "thud"]
];

I want to use ES6's destructuring assignment to get the first element of each array as an individual variable, and repack the rest of the elements as another array. In pseudocode:

for (let [first, *rest] of arrs) { // What is the proper way to do *rest?
    console.log(first); // Should be a number
    console.log(rest); // Should be an array of strings
}

Is something like this possible?

Pointy

That's what ... does:

for (let [first, ... rest] of arrs) {

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to export a part of destructuring assignment?

How can I use this in the left side of the object destructuring assignment?

Can I use destructuring assignment with immutable.js?

Can I pre-declare variables for destructuring assignment of objects?

After destructuring assignment with 'let', can't I ressign a variable of them?

How can I implement destructuring assignment for functional react components props?

How can I restructure this dataframe?

Can the props in a destructuring assignment be transformed in place?

is there a way I can only parse a part of string?

how can i restructure the data frame in R

How can I restructure `if` and `else` statements in PHP

Better way to fill variables from array (Destructuring assignment)

How to namespace Destructuring assignment?

Is this an example of destructuring assignment?

Destructuring assignment, but without a pattern

Python assignment destructuring

Object property assignment with destructuring?

Destructuring assignment for nested properties

Destructuring assignment and variable swapping

Destructuring assignment in object creation

Destructuring assignment and null coalescing

typescript destructuring assignment with interface

Destructuring assignment in Typescript

JavaScript Destructuring Assignment

JS Proxy & destructuring assignment

Why the right side of a destructuring assignment ignores an index increment made in its left part

How can I efficiently restructure my dataset for EDA in pandas?

How to restructure .forEach so I can break out of it

How can I restructure object to Array of objects to a specific format?