Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to structure object in es6 but not getting results.(我想在es6中构造对象,但没有得到结果。)

let animal ={ data:{ typee:{ title: "Cow", legs:4 } } } let {data:{typee:{title,legs}}}=animal; now console.log(data) giving output Error: data is not defined .(现在console.log(data)提供输出Error: data is not defined 。) What I am doing wrong ?(我做错了什么?)   ask by Ashwani Panwar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
209 views
Welcome To Ask or Share your Answers For Others

1 Answer

When destructuring nested objects, the interim values are not assigned to consts/variables.(销毁嵌套对象时,不会将中间值分配给const /变量。)

You'll have to assign them explictly:(您必须明确分配它们:) const animal = {"data":{"typee":{"title":"Cow","legs":4}}}; const { data, // assign the data data: { typee, // assign the typee typee: { title, legs } } } = animal; console.log(data, typee, title, legs);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...