Created
July 19, 2017 11:56
-
-
Save thangarajan8/b6241e9e1538e3bc6961b83e63f62b3d to your computer and use it in GitHub Desktop.
getAllValuesByKey created by thangarajan8 - https://repl.it/J8WP/5
This file contains 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 = [{name: 'rajan', age: 35, favfood: 'icecream'}, | |
{name: 'king', age: 25, favfood: 'bear'}, | |
{name:"thanga", age:27, favfood :"briyani"}]; | |
console.log(users); | |
console.log(users[0].name); | |
function getAllValuesByKey(users,keyName){ | |
var values=[]; | |
for(var i=0;i<users.length;i++){ | |
values.push(users[i][keyName]) | |
} | |
return values; | |
} | |
console.log(getAllValuesByKey(users,"name")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment