Reputation: 27
I have:
[Object, Object]
0:Object
val1 : "123"
name: "John"
1:Object:
val2 : "123"
name: "John"
How i can get values from this array object? I need name values from this two object.
Upvotes: 0
Views: 148
Reputation: 19090
You can use Array.prototype.map() and directly return obj.name
property:
const arr = [{val: "123", name: "John"}, {val: "123", name: "John"}];
const result = arr.map(obj => obj.name);
console.log(result);
Upvotes: 1
Reputation: 8552
As simple as the following code:
const array = [{val: "123", name: "John"}, {val: "123", name: "John"}];
const res = array.map(e => e.name);
console.log(res);
Upvotes: 0