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

129
Views
Mapa que devuelve solo el primer elemento
const list= ['razxDUgYGNAdQ', 'Qwsogvtv82FCd'] const options = { method: 'GET', headers: { 'X-RapidAPI-Key': 'f4f0f6d3c8msh5e07811ecc90234p121a8djsnf83076cfce98', 'X-RapidAPI-Host': 'coinranking1.p.rapidapi.com' } }; fetch(`https://coinranking1.p.rapidapi.com/coins?referenceCurrencyUuid=yhjMzLPhuIDl&timePeriod=24h&${list.map((coin, index) => `uuids[${index}]=${coin}&`)}tiers[0]=1&orderBy=marketCap&orderDirection=desc&limit=50&offset=0`, options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));

En el código anterior, hay 2 elementos en la matriz de list . Y la API obtiene datos para estos 2 elementos (uuids), pero obtengo el resultado solo para el primer elemento. Y si lo hago manualmente sin usar el map , funciona bien, pero podría haber muchos más elementos en la matriz, así que puedo. No lo hagas manualmente.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

En primer lugar, filtró públicamente la clave API aquí, lo que probablemente no sea una buena idea.

Te falta join('') después del mapa:

 const list= ['razxDUgYGNAdQ', 'Qwsogvtv82FCd'] const options = { method: 'GET', headers: { 'X-RapidAPI-Key': 'f4f0f6d3c8msh5e07811ecc90234p121a8djsnf83076cfce98', 'X-RapidAPI-Host': 'coinranking1.p.rapidapi.com' } }; fetch(`https://coinranking1.p.rapidapi.com/coins?referenceCurrencyUuid=yhjMzLPhuIDl&timePeriod=24h&${list.map((coin, index) => `uuids[${index}]=${coin}&`).join('')}tiers[0]=1&orderBy=marketCap&orderDirection=desc&limit=50&offset=0`, options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
 .as-console-wrapper { max-height: 100% !important; top: 0; } /* ignore this */

about 4 years ago · Santiago Gelvez Report

0

Esto está debajo de la función de map js devuelve una matriz. por lo que su código terminaría produciendo algo como, ['uuids[0]= razxDUgYGNAdQ&', 'uuids[1]= Qwsogvtv82FCd&']

lo que en cambio es una función de reducción

 // example list.reduce((perv, curr, index) => perv + `uuids[${index}]=${curr}&`, '')
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!