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

184
Visualizações
how to convert whole array to string in javascript

I got a question in the interview that he asked to convert the whole array into a String. I tried with toString() but that's not worked for his output.

input

let a=['20','30','50']

expected output

"['20','30','50']"
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Assuming the "output" is the content of this string you want, you can map the values first to wrap them in single-quotes, then join the array with commas and wrap the entire thing in "[...]".

const a = ['20','30','50'];

const str = `"[${a.map(v=>`'${v}'`).join(",")}]"`;

console.log(str);

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

let arr = ['1','2','3'];

//this will convert it to string
let arrToString = JSON.stringify(arr);

//you can confirm its type using below code
console.log(typeof(arrToString))
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