0

How to do property destructuring so that I can destructure name and age only

let a={ name:'alex', language:['java','c'], age:30} let {name,,age}=a Console.log(age) I am getting an error saying property destructuring pattern expected.

21st Dec 2022, 10:17 AM
Levi
Levi - avatar
3 Answers
+ 6
Levi Your code is right it has extra comma in second line bwt name and age And in Console.log ...change it into console.log... https://code.sololearn.com/cO67P5MIp4N8/?ref=app It works...
21st Dec 2022, 10:21 AM
Riya
Riya - avatar
+ 3
https://code.sololearn.com/cJ9C9nFuAAJa/?ref=app In this code you can access language too
21st Dec 2022, 10:45 AM
Riya
Riya - avatar
+ 2
possible destructuring: let a={ name:'alex', language:['java','c'], age:30} let {age,...others}=a let {language,name}=others let [x,y]=language console.log(a) console.log(age) console.log(others) console.log(language) console.log(name) console.log(x) console.log(y)
21st Dec 2022, 10:55 AM
Bob_Li
Bob_Li - avatar