I have the following javascript array var rows.
[
{ email: 'user1@example.com' },
{ email: 'user2@example.com' }
]
Of which, I wanted to make it just...
[
'user1@example.com',
'user2@example.com'
]
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:
user1@example.com
entry:
user2@example.com
Any help is appreciated.
You can use Array.prototype.map:
var newArray = oldArray.map(function (obj) {
return obj.email;
});
here is your solution
var rows =[
{ email: 'user1@example.com' },
{ email: 'user2@example.com' }
];
var yop = [];
rows.forEach(function(entry) {
yop.push(entry.email);
});
console.log(yop);