user6372887
user6372887

Reputation:

Angular2 Get value from Array of Objects

How Can I get value from this array? I would like to take from each of Object value as firstPersonName.

enter image description here

I wrote something like this

var rest = email.map(a => {
    a.firstPersonEmail;
});
console.log(rest);

But i am getting

enter image description here

Thanks for any help :)

Upvotes: 1

Views: 4606

Answers (1)

Sayamrat Keawta
Sayamrat Keawta

Reputation: 63

This may help you:

var rest = email.map(a => {
  return a.firstPersonEmail;
});
console.log(rest);

or

var rest = email.map(a => a.firstPersonEmail);
console.log(rest);

const email = [
  {id:1, firstPersonEmail: "[email protected]"},
  {id:2, firstPersonEmail: "[email protected]"},
  {id:3, firstPersonEmail: "[email protected]"}
];

const emptyEmail = [];

console.log(`Email length: ${email.length}`);
console.log(`Empty Email length: ${emptyEmail.length}`);

const rest = email.map(a => a.firstPersonEmail);
const emptyRest = emptyEmail.map(a => a.firstPersonEmail);

console.log(rest);
console.log(emptyRest);

Upvotes: 3

Related Questions