Thursday, 19 September 2013

Javascript: read Array of Objects

Javascript: read Array of Objects

I have two .js files. In one, I want to fill an array with objects, that
have two properties. In the other file I want to loop over the array and
work with the objects properties.
My coding looks like this:
file1.js
var selection = new Object();
selection.column = "";
selection.term = "";
var selectionContainer = new Array();
...
press: function(){
var i;
for (i=1;i<=selectionContainer.length;i++){
selection = selectionContainer[i];
alert("Search Term: " + selection.column + selection.term);
}
}
file2.js
change: function(oEvent){
selection.column = "someText";
selection.term = "someOtherText";
selectionContainer[nrOfEntries] = selection;
}
When executing the javascript I receive 'Uncaught TypeError: Cannot read
property 'column' of undefined'.
What am I doing wrong?
Thanks in advance!

No comments:

Post a Comment