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

164
Visualizações
Problem understanding the .map method in JS

I have an API handler where I want to take an array of unformatted user input and turn it into formatted data.

const _richTextStructure =
  {
    text: { content: null},
  }
;

function stuff2RichText(stuff){
  let obj = _richTextStructure;
  obj.text.content = stuff;
  arr=[obj];
  return arr;}
  
 let sample = ["one", "two", "three"];
 let newSample = sample.map(txt=>stuff2RichText(txt))
 
  console.log(newSample)

Now I would expect this to return "one", "two" and "three", wrapped in the RT structure, but instead it gives me:

[[{
  text: {
    content: "three"
  }
}], 
[{
  text: {
    content: "three"
  }
}], 
[{
  text: {
    content: "three"
  }
}]]

Could anyone explain why this doesn't work when e.g. sample.map(txt=>txt.toUppercase) returns exactly what you'd expect?

about 4 years ago · Santiago Trujillo
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