0

Goal: Trying to filter a dataset by entries with working image links. Currently using the following function imageExists() to return true or false, and trying to test d.URL against that logical test in the filter function.

Problem: It's returning an empty array.

function imageExists(url){
    var image = new Image();
    image.src = url;
    if (!image.complete) {
        return false;
    }
    else if (image.height === 0) {
        return false;
    }
    return true;
}


d3.json("data.json", function(data) {
            data.forEach(function(d) {
                d.URL = +d.URL;
                 });

            working_photos = data.filter(function(d) { 
                    return imageExists(d.URL) == true;
                    });
            console.log(working_photos);
});
Emily Chu
  • 187
  • 3
  • 15

0 Answers0