L
L
laguna11322018-05-04 06:02:40
JavaScript
laguna1132, 2018-05-04 06:02:40

How to output n number of elements in React?

I have some variable count. I need to put count elements into template html variable. For example, if count = 4, then template must be equal to = " ". How to implement it? <td></td><td></td><td></td><td></td>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-05-04
@laguna1132

let count = 4
let template = Array(count).fill('<td></td>').join('')


console.log(template) 
// -> <td></td><td></td><td></td><td></td>

or like this:
let template2 = '<td></td>'.repeat(count)

A
Alexander, 2018-05-04
@alexr64

while (i <= count)
{
template  = template + "<td></td>"
i++
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question