How to access just the values in an Object.Entries() so React doesn't give me a warning?

Viewed 81

React gives me an error:

'key' is assigned a value but never used

But I don't need to use the keys ever, so how do I work around this?

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);
            }
        }
...
2 Answers

You can do the following, discarding the first entry since it isn't used (note the comma):

for (const [, value] of Object.entries(obj)) {

use this code.

let user = {
name: "John",
age: 30
};
// loop over values
for (let value of Object.values(user)) {
  alert(value); // John, then 30
}
Related