0

I want to render some data got from API response and as the code below ,temp array can show but list array can't. this picture link showes the render result

Which I use push() can render sucessfully but which I use for loop to change value in array can't render sucessfully.

I want to know how to fix it, thanks a lot.

let list = JSON.parse(JSON.stringify(responses))
for (let i = 0; i < list.length; i++) {
  for (let j = 0; j < list[i].length; j++) {
    list[i][j] = `<li>${list[i][j]}</li>`
  }
}
let temp = []
for (let i = 0; i < responses.length; i++) {
  temp.push(
    <li className="ssl">
      <div className="box">
        <h3>{responses[i][0]}</h3>
          <ul className="ee">{list[i]}</ul>
      </div>
    </li>
  )
}
setResult(temp)
2
  • 1
    Why you need JSON.parse(JSON.stringify(responses)) this line ? Commented Aug 24, 2022 at 9:08
  • deep copy the responses from API , to prevent modify the origin data. Is that unnecessary? Commented Aug 24, 2022 at 11:35

1 Answer 1

2

Just change the following

list[i][j] = `<li>${list[i][j]}</li>`

to

list[i][j] = <li>{list[i][j]}</li>

That's it.

Sign up to request clarification or add additional context in comments.

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.