Last active
September 27, 2018 01:44
-
-
Save JimmyCheng/6c95796f51867b60fada2d9a081ff0da to your computer and use it in GitHub Desktop.
lodash map without iterator functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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