I'm having problem while implementing load more using JavaScript. Can anyone please help?
I've tried using for loops. As I'm a beginner to JavaScript, I was able to implement a little.
<script>
let ar = ['a', 21, 'b'];
let postToShow = 1;
function load(val) {
for (let i = 0; i < ar.length; i++) {
if (postToShow % (ar.length + 1) !== 0) {
document.getElementById('num').innerHTML += ar[postToShow - 1] + "<br />";
postToShow++;
return;
}
}
}
</script>
<body>
<button onclick="load()" id="loadMore">Load more </button>
</body>
I expect output to be loaded based on postToShow. Please help...
{}in the editor to format it