I am trying to add property name and value from 'for loop'. However it is not working in object case. But if I use HTML form it works fine.
var interestListsObj = {}
interestLoop:function(interestList){
var text = "";
for(var i=0; i<interestList.length; i++) {
text += "<option value='"+interestList[i].machine_name+"'>"+ interestList[i].name + "</option>";
/*line no 6*/ interestListsObj.interestList[i].machine_name = interestList[i].name;
}
$("#listOfInterest").html(text);
console.log(interestListsObj)
},
In the above code if I remove the 'line no 6' then it works fine. But not sure what is wrong with the line no 6. The loop exit automatically without desire result.
interestListlooks like? Are you getting any errors right now?[]notation for creating and accessing dynamic properties..won't work here. ChangeinterestListsObj.interestList[i].machine_nametointerestListsObj[interestList[i].machine_name]interestList[i].machine_nameas a key for his object. He'll have to use theinterestListsObj[interestList[i].machine_name]for that,.won't work