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

130
Views
Haga coincidir los valores de dos matrices en una nueva matriz usando id

Así que tengo una matriz que tiene esta estructura

 [{id:'bitcoin', change:-5.5}]

Nuevamente tengo otra matriz que tiene criptos en este formato.

 [{ id: 'bitcoin', symbol: 'BTC', name: 'Bitcoin', img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/1200px-Bitcoin.svg.png', addr: '0xECe365B379E1dD183B20fc5f022230C044d51404' },]

Eso es solo un ejemplo, las matrices tienen múltiples objetos de datos. Estoy transformando la matriz criptográfica en una nueva matriz porque estoy calculando su precio de mercado en tiempo real usando cada dirección de moneda como esta

 for (let i = 0; i < this.assets.length; i++) { coinValue = await getPrice(this.assets[i].addr); this.transformedAssets.push({ id: this.assets[i].id, symbol: this.assets[i].symbol, name: this.assets[i].name, img: this.assets[i].img, addr: this.assets[i].addr, value: numberWithCommas(coinValue) }); }

Ahora también quiero pasar coin_24h_percentage_change a la nueva matriz porque la matriz criptográfica y la matriz de cambio porcentual tienen una identificación común que puede vincularlas, pero no sé cómo hacerlo.

Hice algo como esto pero no funciona ¿Cómo se supone que debo hacer que esto suceda?

 for (let i = 0; i < this.assets.length; i++) { coinValue = await getPrice(this.assets[i].addr); const price_change_percentage_24h = JSON.parse(JSON.stringify(this.coinPerfomance[0].change)); window.console.log(price_change_percentage_24h); this.transformedAssets.push({ id: this.assets[i].id, symbol: this.assets[i].symbol, name: this.assets[i].name, img: this.assets[i].img, addr: this.assets[i].addr, daychange: this.coinPerfomance[this.assets[i].id].change, value: numberWithCommas(coinValue) }); }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puedes intentar algo como esto:

 let priceChange = [{id:'bitcoin', change:-5.5}]; let data = [ { id: 'bitcoin', symbol: 'BTC', name: 'Bitcoin', img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/1200px-Bitcoin.svg.png', addr: '0xECe365B379E1dD183B20fc5f022230C044d51404' } ]; let result = data.map(el => ({...el, 'change': priceChange.find(pc => pc.id == el.id).change})); console.log(result);
about 4 years ago · Santiago Gelvez 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!