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

98
Visualizações
Add single quotes in a string array javascript

I been searching for the solution but can't find it...

I have the following array with the following output:

['Fruits, Cars, Clothes, Shoes']

But I need the that array to output the following:

['Fruits', 'Cars', 'Clothes', 'Shoes']

I already tried the following and it did not work:

var output= arr.map(item => "'" + item + "'").join();

Can you help please

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

0

Just get the first (and unique) item of your array, then split it and trim every element:

const arr = ['Fruits, Cars, Clothes, Shoes'];

const newArr = arr[0].split(',').map(x => x.trim());

console.log(newArr);

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