I have a million doubt, is there the possibility of only extracting the values of an object (key) in javascript?
[
{
name: "Sucursal 1",
data:
[
{id: 1, usuarios: 3},
{id: 2, usuarios: 0},
{id: 3, usuarios: 5},
{id: 3, usuarios: 2}
]
},
{
name: "Sucursal 2",
data:
[
{id: 1, usuarios: 9},
{id: 2, usuarios: 10},
{id: 3, usuarios: 4},
{id: 3, usuarios: 3}
]
},
{
name: "Sucursal 3",
data:
[
{id: 1, usuarios: 0},
{id: 2, usuarios: 1},
{id: 3, usuarios: 3},
{id: 3, usuarios: 4}
]
}
]
What I try to build based on that object is the following:
[
{
name: "Sucursal 1",
data: [3, 0, 5, 2]
},
{
name: "Sucursal 2",
data: [9, 10, 4, 3]
},
{
name: "Sucursal 3",
data: [ 0, 1, 3, 4]
}
]
I tried using push
, I also tried using ForEach to iterate through the object, but got lost trying.
You can do two
map()
nested:You can use the function
reduce
to extract only the values fromusuarios
within the array of objectsdata
:My option for this problem would be to use _Underscore:
Separated into two functions for readability, just put in SelectArrayValues(x) your original array. It does not return another array, but only modifies the necessary part.