Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!