显示空值的字段值

问题描述 投票:0回答:1
const book1 = this.state.books[0]; //giving one book
console.log(book1);
output->{id: 1, bookname: "Physics", price: 600, author: "ABC", pages: 567, …}
const {id,bookname,price,author,pages,category} = {book1};
console.log(price);
output->undefined
Already tried a lot of things.
How To get the value of particular property?
Here is the JSON FILE.

[{“ id”:1“ bookname”:“ Physics”,“价格”:600,“ author”:“ ABC”,“页面”:567,“类别”:“科学”}

]

json reactjs output undefined state
1个回答
0
投票
显示的JavaScript对象解构无效。更改为此:

const { price } = book1;

© www.soinside.com 2019 - 2024. All rights reserved.