How to use object destructuring to assign values in JavaScript

2 Answers

0 votes
const user = {
    id: 18905,
    age: 50
};

const {id, age} = user;

console.log(id); 
console.log(age); 




/*
run:

18905
50

*/

 



answered Nov 13, 2020 by avibootz
0 votes
const user = {
    id: 18905,
    age: 50
};
 
const {id: a, age: b} = user;
 
console.log(a); 
console.log(b); 
 
 
 
 
/*
run:
 
18905
50
 
*/

 



answered Nov 14, 2020 by avibootz
...