互联网技术 · 2024年2月19日

ES6中的数组对象解构语法{}

//数组对象 const people = [ {name:Henry,age:20}, {name:Bucky,age:25}, {name:Emily,age:30}, ]; // 需求,取第一个age // es5 var age = people[0].age; console.log(age)//20 // es6解构 const [age] = people; /** * 因为第一层解构的是数组,所以会返回第一条的整条数据 */ console.log(age)//{ name: Henry, age: 20 } /** * 如果想拿第一条数据的age值就得再解构一次 */ const [{age}] = people; console.log(age)//20

文章来源:田珊珊个人博客

来源地址:http://www.tianshan277.com/682.html

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册