Skip to content

Instantly share code, notes, and snippets.

@thangarajan8
Created July 19, 2017 11:56
Show Gist options
  • Save thangarajan8/b6241e9e1538e3bc6961b83e63f62b3d to your computer and use it in GitHub Desktop.
Save thangarajan8/b6241e9e1538e3bc6961b83e63f62b3d to your computer and use it in GitHub Desktop.
getAllValuesByKey created by thangarajan8 - https://repl.it/J8WP/5
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