Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

destructure object in javascript es6 when keys are integers [duplicate]

When we have an object in JS like

var obj = {a: "apple", p: "pen"};

then we can destructure it as follows

 var {a, p} = obj; /* a = 'apple', p = 'pen' */

i want to know in case when keys are integers, how can we destructure it ? since we cannot declare integers as variable name

 var obj = {0: 'pineapple', 1: 'pen'};
like image 318
Vikramaditya Avatar asked Dec 15 '16 06:12

Vikramaditya


1 Answers

Just like any other assigning to new variable names

var {0:a, 1:b} = obj;
like image 106
Artem Dudkin Avatar answered Oct 17 '22 07:10

Artem Dudkin