Created
March 23, 2018 09:04
-
-
Save josephdicdican/4ad20a54639e6f2bf7b49c29ff825149 to your computer and use it in GitHub Desktop.
JS Array Map
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
var users = [ | |
{ id: 1, name: "Joseph" }, | |
{ id: 2, name: "Tressa" } | |
]; | |
var user_names = users.map((user) => { | |
return user.name; | |
}); | |
console.log('names', user_names); | |
// will produce >>> ["Joseph", "Tressa"] | |
var usernames_formatted = users.map((user, key) => { | |
var name = user.name; | |
return (key%2 == 0) ? name.toLowerCase() : name; | |
}); | |
console.log('formatted', usernames_formatted); | |
// will produce >>> ["joseph", "Tressa"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment