Hello I have a prboblem with the next code:
function loadOptions(num){
listTabs = new Array();
for(var i = 1 ; i < parseInt(num) + 1 ; i++){
var tabActu = {
'name':'tab'+i,
'src':'urlImatge'
};
listTabs.add(tabActu);
$.each(listTabs,function(key,value){
alert(key+" : "+value);
});
}
}
I need to create an list of elements equal to the num parameter. I can’t find the error.
Did you look in the error console for javascript errors?
Javascript arrays don’t have a
.add()method. You can use.push().In addition to change to
.push(), parseInt must always be passed the radix value and you should remove the function call to parseInt from the loop so it’s not called on every iteration. Also, you haven’t delcared listTabs here so that makes it a global variable. Is that what you intended?