0

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.

3
  • 5
    Please post yout code, not console.log() result ;) Commented Jun 9, 2017 at 7:35
  • Define values? Commented Jun 9, 2017 at 7:36
  • 2
    array.map( object => object.name ) Commented Jun 9, 2017 at 7:37

2 Answers 2

1

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);

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.