Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda