I am getting an array of data containing many parameters. For example, the data array is in the below format:
var data = [
{
"name":"pradeep",
"age": "32",
"location": "Bangalore"
},
{
"name":"praveen",
"age": "30",
"location": "Mangalore"
},
{
"name":"Ajay",
"age": "32",
"location": "Hubli"
}
]
I want the above array to be reduced to the below format:
[
{
"name":"pradeep"
},
{
"name":"praveen"
},
{
"name":"Ajay"
}
]
How to get this done using Underscore. I tried using the _.pluck but it fetches only the data and not the key.
_.pick, then I realised the OP wants an array of objects andpickonly works on single objects._.pick()is best suited for when there are multiple keys to be copied, and/or when the keyname is variable.