“javascript es6 trouver” Réponses codées

javascript es6 trouver

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

trouver dans js

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

Réponses similaires à “javascript es6 trouver”

Questions similaires à “javascript es6 trouver”

Plus de réponses similaires à “javascript es6 trouver” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code