2๐
โ
const a = [
{
"0": {
"itog": 12860498,
"return": 1107294,
"beznal": 10598131
},
"date": "2021-01-31"
},
{
"0": {
"itog": 20156554,
"return": 1147363,
"beznal": 18127393
},
"date": "2021-02-28"
},
{
"0": {
"itog": 19187309,
"return": 1667656,
"beznal": 17597434
},
"date": "2021-03-31"
}
];
const result = a.map(function(i) {
return i[0].itog;
});
console.log( result );
๐คHitesh Lala
1๐
You can use Array.map to get it.
var input = new Array({
"0": {
"itog": 12860498,
"return": 1107294,
"beznal": 10598131
},
"date": "2021-01-31"
},
{
"0": {
"itog": 20156554,
"return": 1147363,
"beznal": 18127393
},
"date": "2021-02-28"
},
{
"0": {
"itog": 19187309,
"return": 1667656,
"beznal": 17597434
},
"date": "2021-03-31"
}
);
var output = input.map(item => item[0]['itog']);
console.log(output);
๐คTuan Dao
0๐
Please accept one of the previous solutions, they are perfect for what you need.
A more generic solution could be:
const data = [
{
"0": {
"itog": 12860498,
"return": 1107294,
"beznal": 10598131
},
"date": "2021-01-31"
},
{
"0": {
"itog": 20156554,
"return": 1147363,
"beznal": 18127393
},
"date": "2021-02-28"
},
{
"0": {
"itog": 19187309,
"return": 1667656,
"beznal": 17597434
},
"date": "2021-03-31"
}
];
let itogs = [];
data.forEach(entry => {
itogs = [
...itogs,
...Object.values(entry)
.map(obj => obj['itog'])
.filter(itog => itog)
];
});
console.log(itogs);
๐คLaszlo Gazsi
Source:stackexchange.com