JSFiddle - React, Tailwind, and code Playground

HTML

<img id="MyImgBg" src="" alt="" />

JavaScript

// A bunch of images
var arrImages = ["http://i.imgur.com/cKUVXuQ.jpg","http://i.imgur.com/Ei598tR.jpg","http://i.imgur.com/W92PhqU.jpg"];

// Iterate until I find the first one meeting my specs
$.each(arrImages, function(i,item) 
{
    extension = item.slice(-(3)).toLowerCase();
	if (extension == "jpg")
	{
		// Test image size
		newImg = new Image();
		newImg.onload = function() 
		{			
			if (this.width > 600 && this.height > 900)
			{
                // All right! That's the one. Set it as src on my web page
				$("#MyImgBg").attr("src",this.src);
                return false; // trying to break out - not working
			}			
		};
        newImg.src = item;
    }
    
    // I expected this alert to popup only twice
    alert(i); 
    
});