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.
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 */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}&`, '')