-4
[
  {
    "date": "2021-02-01",
    "retail": 115404,
  },
  {
    "date": "2021-02-02",
    "retail": 100325,
  },
  {
    "date": "2021-02-03",
    "retail": 99414,
  },
  {
    "date": "2021-02-04",
    "retail": 96167,
  },
  {
    "date": "2021-02-05",
    "retail": 94092,
  },
]

Подскажите как из этого вернуть новый массив [115404,100325,99414,96167,94092]

3 ответа 3

3

сложный вопрос, но попытаюсь предположить, что так:

const arr = arr.map(i => i.retail);
2
let array = [
  {
    "date": "2021-02-01",
    "retail": 115404,
  },
  {
    "date": "2021-02-02",
    "retail": 100325,
  },
  {
    "date": "2021-02-03",
    "retail": 99414,
  },
  {
    "date": "2021-02-04",
    "retail": 96167,
  },
  {
    "date": "2021-02-05",
    "retail": 94092,
  },
];

let newArray = [];

array.forEach(function(item){
  newArray.push(item.retail);
});
1
const arr= [
  {
    "date": "2021-02-01",
    "retail": 115404,
  },
  {
    "date": "2021-02-02",
    "retail": 100325,
  },
  {
    "date": "2021-02-03",
    "retail": 99414,
  },
  {
    "date": "2021-02-04",
    "retail": 96167,
  },
  {
    "date": "2021-02-05",
    "retail": 94092,
  },
];
const res = Array.from(arr, n => n.retail); 
console.log(res;)// [115404, 100325, 99414, 96167, 94092]
1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.