Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141307

Destructuring an array and its properties at the same time

$
0
0

Is it possible to destructure elements of an array while also destructuring some of its properties as an object ?

For example, the following code compiles but doesn't give the expected result :

const array = [1, 2, 3]
array.myvalue = 'test'

function f([a, b, ...{ myvalue }]) {
  console.log(a, b, myvalue);
}

f(array)

Output :

1 2 undefined

Viewing all articles
Browse latest Browse all 141307

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>