How to filter a loop.?

How can I filter numbers from a loop so that.

for(let i = 1; i <= 57; i++) {
                display += `
          <div class="card">
            <h4>No: ${[i]}</h4>
            <h4>${res[i]}</h4>
          </div>

              `;
            }

so that when I enter a number lets say 10, only number 10 is shown. ?

You’ll need to explain a bit more of what you’re trying to do here because at the minute you’re just printing 57 of those elements, what do you mean by “if you enter a number”?

Not sure why you need a loop here. Either just fetch the quotes every time and return the one you want. Or load loads of quotes when you open the page and store them in a variable, then just pick one and render it based in what the user inputs.

1 Like

Yep, you should load them into an array for example and if in the beginning you want to show all of them, then just map over the array and if you want to filter it after the user input, you can use filter. ^^ :wink: