Skip to content

Instantly share code, notes, and snippets.

@lucas-nguyen-17
Last active July 10, 2020 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucas-nguyen-17/6bd24593f95bbf9d2880af6d7233f335 to your computer and use it in GitHub Desktop.
Save lucas-nguyen-17/6bd24593f95bbf9d2880af6d7233f335 to your computer and use it in GitHub Desktop.
Get array based on condition
var users = [
{ 'id': '123', 'name': 'giang' },
{ 'id': '456', 'name': 'nguyen' },
{ 'id': '789', 'name': 'nguyen' }
];
var filters = _.filter(users, function(user) {
return user.name === 'nguyen';
});
var ids = _.map(filters, 'id');
console.log(ids)
//show ["456", "789"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment