简体   繁体   English

如何使用数组解构提取嵌套的 object 属性?

[英]How to extract nested object property using array destructuring?

I get undefined using this code:我使用此代码未定义:

 const json = {"records":[{"recordid":"1694119","recordindex":1,"status":"updated successfully"}],"message":{"returncode":1}}; const { records: {status} } = json; console.log(status);

How to get the expected: "updated successfully"?如何获得预期的:“更新成功”?

Since records is an array, you need to add brackets:由于records是一个数组,所以需要加上括号:

 const json = {"records":[{"recordid":"1694119","recordindex":1,"status":"updated successfully"}],"message":{"returncode":1}}; const { records: [{status}] } = json; console.log(status);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM