const data = { user: [ { name: 'jack' } ] }
How do I get only Jack when I call the constant.
const data = { user: [ { name: 'jack' } ] }
How do I get only Jack when I call the constant.
It is saved as an array. To use its components, you must do the following:
data.user[0].name;
data.user[1].name;
data.user[1].age;
If you want foreach loop in JS you can do like this : @EDIT 1 updated without this
const data = [{name:"Jack", age:"50"},{name:"Brook", age:"20"},{name:"Noob", age:"34"}];
for(const n of data) {
console.log(n.name)
console.log(n.age)
}
@EDIT2
const data = {user : [{name:"Jack", age:"50"},{name:"Brook", age:"20"},{name:"Noob", age:"34"}]};
for(const n of data.user) {
console.log(n.name)
console.log(n.age)
}