Skip to content

Combined Array and Object Destructuring in JavaScript

Array destructuring assigns the properties of an array to variables with the same names by default. Object destructuring assigns the properties of an object to variables with the same names by default. Here is an example.

const props = [
  { A: 1, a: 'one' },
  { B: 2, b: 'two' },
  { C: 3, c: 'three' }];
const [ ,{ B,b },{c}] = props; 
//A,a undefined, B=2,b='two', C undefined, c='three'

Source

See also  Object destructuring in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.