Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Map returning only first element
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));

In the code above, there are 2 items in the list array. And the API fetches data for these 2 items(uuids) but I'm getting the result only for first element And if I do it manually without using map it is working fine but there could be many more items in the array so I can't do it manually.

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

First of all, you publicly leaked api key here, which is probably not a good idea.

You are missing join('') after map:

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 Relatório

0

This is below the js map function returns back an array. so your code would end up producing something like, ['uuids[0]= razxDUgYGNAdQ&', 'uuids[1]= Qwsogvtv82FCd&']

what you instead is a reduce function

// example
list.reduce((perv, curr, index) => perv + `uuids[${index}]=${curr}&`, '')
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda