Reputation: 1159
I have the following javascript array var rows.
[
{ email: '[email protected]' },
{ email: '[email protected]' }
]
Of which, I wanted to make it just...
[
'[email protected]',
'[email protected]'
]
So, I tried to loop it using forEach
rows.forEach(function(entry) {
console.log('entry:');
console.log(entry.email);
});
However, I am stuck with that.
entry:
[email protected]
entry:
[email protected]
Any help is appreciated.
Upvotes: 0
Views: 498
Reputation: 1335
here is your solution
var rows =[
{ email: '[email protected]' },
{ email: '[email protected]' }
];
var yop = [];
rows.forEach(function(entry) {
yop.push(entry.email);
});
console.log(yop);
Upvotes: 2
Reputation: 166031
You can use Array.prototype.map
:
var newArray = oldArray.map(function (obj) {
return obj.email;
});
Upvotes: 9