JSFiddle - React, Tailwind, and code Playground

by Ulugbek Aripov

HTML

<!DOCTYPE html>
<html>
<body>

<p>Click the button to loop through using forEach - equivalent of break at reaching 'Apple'.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
let result="";
function myFunction() {
    var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
    var fruitsToLoop = fruits.slice(0, fruits.indexOf("Apple"));
    fruitsToLoop.forEach(el => {
		result += el + "; ";
	});
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>