maria maria - 21 days ago 6
AngularJS Question

JavaScript make object to array only by messageid

Let's say I have the following:

[
{ messageid: '582b4350af7cb8f21e4b7b43',
_id: 582b4c79105387dd21e08004 } ,
{ messageid: '582b4350af7cb8f21e4b7xb43',
_id: 582b4c79105387dd21e08s004 }

]


How can I make it produce a array that would only be the
messageid
`s values?

Like:

{582b4350af7cb8f21e4b7b43,582b4350af7cb8f21e4b7xb43}
?

Note: plain javascript or angular

Answer

You can use .map

var output = input.map(function(item) {
  return item.messageid;
});

This will create an array that will look like [582b4350af7cb8f21e4b7b43,582b4350af7cb8f21e4b7xb43]