Harry  Liu
Harry Liu

Reputation: 1

Parse Uncaught TypeError: Cannot read property 'get' of undefined

This is my code:

var images = new Parse.Query("Images");
var bunny_data = [];

images.equalTo("indexImg","T");
images.find({
    success: function(objects) {
        for(var i = 0;i<=objects.length;i++){
            var object =  objects[i];
            object.get('imgUrl');

        };
    },
    error: function(error) {
        console.log("An error occured :(");
    }
});
console.log(bunny_data);

The console is:

[]
myjs.js:65 Uncaught TypeError: Cannot read property 'get' of undefined

Upvotes: 0

Views: 915

Answers (1)

Ry-
Ry-

Reputation: 224983

for(var i = 0;i<=objects.length;i++){

The <= means this loops from 0 to objects.length inclusive, but length is an exclusive upper bound on an array’s indices. Use < instead.

Upvotes: 1

Related Questions