I am trying to create a dynamic array and push elements to it using Javascript. Being a beginner, I am having problems with it.
P.S. I am fetching the values all fine (checked with console.log), the only problem is that I am unable to put it in the database.
Below is my code -
(function makelist() {
var listHeaderData =[];
var listChildData = [];
var listImagePath = [];
var nextPageRefLink = ['imageSlider.html','NewsItem_descp_1.html','http://www.yahoo.com'];
Parse.initialize("XN0sv3fBqB380fCpwohuHAgansghkiDp8MhbyJDs", "xzoETxUUxicHAtdwqbZh65XtTAFaona3a6cC9jSB");
console.log("Parse Initailized inside javascript");
var newsFeed = Parse.Object.extend("NewsFeed");
var query = new Parse.Query(newsFeed);
query.find ({
success: function(results) {
var output ="";
for(var i in results) {
//listHeaderData DATA
var heading = results[i].get("Heading");
listHeaderData.push(heading);
console.log("Header : "+heading);
//listChildData DATA
var description = results[i].get("description");
listChildData.push(description);
console.log("Description : "+description);
if(results[i].get("Image")) {
var file = results[i].get("Image");
//listImagePath URL's
var url = file.url();
listImagePath.push(url);
console.log("Image URL is:"+url);
}
console.log("Heading:"+heading);
console.log("Description:"+description);
}
} , error: function(error){
console.log("Query error :"+error.message);
}
});
}
The problem is nothing is getting added to the arrays that I have defined above. I am using .push() function for it. What can be the problem ?
for(var i=0; i < results.length; i += 1)for a start as you don't want to be checking all the properties on theresultsobject, just the array values.