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

519
Visualizações
JavaScript - how to make form String to Array?

I have data const { data: communityData } = useQuery(SEE_ALL_COMMUNITIES_QUERY);

communtyData is Array and it has field named communityName.

if I console.log communityData.communityName[0] then 'abs' comes.

I need to make array looks like below with this 'abs'

 [
   { label: "abs", value: "abs" },
   { label: "gsd", value: "gsd" },
 ]

So I use map function.

  const communityNameList = communityData.seeAllCommunities.map(
    (community, index) =>
      `label:${community.communityName}, value:${community.communityName} }`
  );

I console.log communityNameList,

 Array [
  "{ label:abs, value:abs }",
]

As you can see it has " front and behind the each object. And I dont' know how to put " besides abs.

Please help me

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You don't want to turn this into an Array but into JSON specifically if you want to get the effect you wrote the map should look like this

const communityNameList = arr.map((community, index) => {
    return {
        "label": community.communityName,
        "value": community.communityName
    };
});
about 4 years ago · Juan Pablo Isaza Relatório

0

Try something like this :

const communityNameList = communityData.seeAllCommunities.map(community => ({
        label: community.communityName, 
        value: community.communityName 
    })
);

Note : When you want to return JSON from arrow function you have to surround the return statement with ()

about 4 years ago · Juan Pablo Isaza 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