I would like to load multiple image with JavaScript and wrote the code below. I expected it should output "0 1 2" but unfortunately it output just "3" once. I don't know Why. Anyone, please help me!!
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript">
for (var i = 0; i < 3; i++) {
var imageObj = new Image();
imageObj.addEventListener('load', function() {
console.log(i);
});
imageObj.src = './assets/REACT.png';
}
</script>
</body>
</html>