Reactjs 如何只访问Object.Entries()中的值,以便React不会给我警告?
React给了我一个错误:Reactjs 如何只访问Object.Entries()中的值,以便React不会给我警告?,reactjs,object,Reactjs,Object,React给了我一个错误: 'key' is assigned a value but never used 但我从来都不需要用钥匙,所以我该如何解决这个问题呢 for (const [key, value] of Object.entries(obj)) { if (value === 'null') { let random = Math.floor(Math.random() * 101); arr.
'key' is assigned a value but never used
但我从来都不需要用钥匙,所以我该如何解决这个问题呢
for (const [key, value] of Object.entries(obj)) {
if (value === 'null') {
let random = Math.floor(Math.random() * 101);
arr.push(random);
} else {
let newValue = parseInt(value);
arr.push(newValue);
}
}
...
您可以执行以下操作,放弃第一个条目,因为它未被使用请注意逗号:
for (const [, value] of Object.entries(obj)) {
您可以执行以下操作,放弃第一个条目,因为它未被使用请注意逗号:
for (const [, value] of Object.entries(obj)) {
使用此代码
let user = {
name: "John",
age: 30
};
// loop over values
for (let value of Object.values(user)) {
alert(value); // John, then 30
}
使用此代码
let user = {
name: "John",
age: 30
};
// loop over values
for (let value of Object.values(user)) {
alert(value); // John, then 30
}