2

Is there a way to render something like this: ["1", "2","3"] as1,2,3,4,5 in React?

render(){
  <p>{this.numberResult()} </p> 
}

this.numerResult returns ["1", "2","3"] which ends up looking like: 123 in the browser but I would like it to return 1,2,3

3 Answers 3

3

Use join().

Sample Example:

const joined = ["1", "2","3"].join(",")
console.log(joined);

render(){
  <p>{this.numberResult().join(",")} </p> 
}
Sign up to request clarification or add additional context in comments.

Comments

2

If you want to show numbers comma separeted, use join:

render(){
  <p>{(this.numberResult() || []).join(', ')} </p> 
}

Comments

1
render(){
  <p>{this.numberResult().join(", ")</p> 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.