Skip to content

Instantly share code, notes, and snippets.

@JimmyCheng
Last active September 27, 2018 01:44
Show Gist options
  • Save JimmyCheng/6c95796f51867b60fada2d9a081ff0da to your computer and use it in GitHub Desktop.
Save JimmyCheng/6c95796f51867b60fada2d9a081ff0da to your computer and use it in GitHub Desktop.
lodash map without iterator functions
//The map function in lodash is quite frequently used. e.g.:
const team = [{"name": "jimmy", "rate": 100}, {"name": "tom", "rate": 88} ];
_.map(team, t=>t.rate + 1);
//so normaly the iteration function is provided. But what if the iteration function is not there?
const team = [{"name": "jimmy", "rate": 100}, {"name": "tom", "rate": 88} ];
const b = _.map(team);
console.log(b); //give the same result.
//actually it can be useful in this case:
const team = {"manager": {"name": "jimmy", "rate": 100}, "member": {"name": "tom", "rate": 88}, "member": {"name": "jack", "rate": 88}};
console.log(_.map(team));
//The object is extracted and built to an array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment