Array value problem

var value = [{"value": {"year": 2018, "month":3, "count": 123}},{"value": {"year": 2018, "month":12, "count": 68}}];//
var value = [ {"year": 2018, "month":3, "count": 123},{"year": 2018, "month":12, "count": 68}]//

Feb.02,2022

var result = value.map(x => x.value);

use map function

> var value = [{'value': {'year': 2018, 'month':3, 'count': 123}},{'value': {'year': 2018, 'month':12, 'count': 68}}];
undefined
> value.map(v=> v.value)
[ { year: 2018, month: 3, count: 123 },
  { year: 2018, month: 12, count: 68 } ]
>

var value = [{'value': {'year': 2018, 'month':3, 'count': 123}},{'value': {'year': 2018, 'month':12, 'count': 68}}];
var valueResult = value.map((item)=>{
    return item.value
});
:valueResult =[ {'year': 2018, 'month':3, 'count': 123},{'year': 2018, 'month':12, 'count': 68}]

for loop to construct new objects; it's easier to use Map directly.

Menu