Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

66
Views
Return a new array from the data from json

Help to return a new array from the data from json. At the output I want to get array of itog

[12860498,20156554,19187309]

[
      {
        "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"
      }
    ]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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 );

about 4 years ago · Juan Pablo Isaza Report

0

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);

about 4 years ago · Juan Pablo Isaza Report

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!