“javaScript es6 Найти” Ответ

javaScript es6 Найти

const originalData = [
  { "investor": "Sue",   "value":  5,   "investment": "stocks"  },
  { "investor": "Rob",   "value": 15,   "investment": "options" },
  { "investor": "Sue",   "value": 25,   "investment": "savings" },
  { "investor": "Rob",   "value": 15,   "investment": "savings" },
  { "investor": "Sue",   "value":  2,   "investment": "stocks"  },
  { "investor": "Liz",   "value": 85,   "investment": "options" },
  { "investor": "Liz",   "value": 16,   "investment": "options" },
];

const newData = [
  { "investor": "Sue",   "stocks": 0,   "options": 0,   "savings": 0 },
  { "investor": "Rob",   "stocks": 0,   "options": 0,   "savings": 0 },
  { "investor": "Liz",   "stocks": 0,   "options": 0,   "savings": 0 },
];

for (let {investor, value, investment} of originalData) {
  newData.find(x => x.investor === investor)[investment] += value;
}

console.log(newData);
Arrogant Addax

Найти в JS

The first element that will be found by that function
const f = array1.find(e => e > 10);
EON

Ответы похожие на “javaScript es6 Найти”

Вопросы похожие на “javaScript es6 Найти”

Больше похожих ответов на “javaScript es6 Найти” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования