I would like to extract all the properties of a homogeneous JSON collection into my own array.
For example, given:
var dataPoints = [
{
"Year": 2005,
"Value": 100
},
{
"Year": 2006,
"Value": 97
},
{
"Year": 2007,
"Value": 84
},
{
"Year": 2008,
"Value": 102
},
{
"Year": 2009,
"Value": 88
},
{
"Year": 2010,
"Value": 117
},
{
"Year": 2011,
"Value": 104
}
];
I would like to extract an array of all values ββfrom dataPoints, which looks something like this:
var values = [100, 97, 84, 102, 88, 117, 104];
Instead of iterating and constructing manually, is there a clean / efficient way to do this transposition?
source
share