1

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?

IsakE
  • 55
  • 5

0 Answers0