“JavaScript ES6 Find” Respostas de código

JavaScript ES6 Find

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

Encontre em JS

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

Respostas semelhantes a “JavaScript ES6 Find”

Perguntas semelhantes a “JavaScript ES6 Find”

Mais respostas relacionadas para “JavaScript ES6 Find” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código