This is probably something really stupid but for the life of me i can't see it.
I have code that fills an array with strings and ii then want to loop through the array and add the values to as options in a select control. But for some reason when i call the length property it returns 0, but if i use console.dir to display the array in the console it has data in it.
here's the code:
var sectors = new Array();
// code to add values
$.getJSON("get/tech_info.php", {uid:json.uid}, function(data){
$.each(data, function(i, json){
if($.inArray(json.area, sectors) == -1)
{
sectors[sectors.length] = json.area;
}
});
});
console.dir(sectors);
var sec = "#mainSectors" + count;
console.log(sectors.length); // returning 0
for ( var i=0; i != sectors.length; i++ ){
console.log("bla bla bla");
$(sec).append(
$("<option></option>").html(sectors[i])
);
}
Here's the cosole.dir data which you can see has data:
//secotrs
Array[0]
0: "Industrial"
1: "Commercial"
length: 2
__proto__: Array[0]
console.dir? And the code where you add values?// code to add values goes here //.sectors[0] = "Industrial", thensectors[0].lengthshould show10(the length of the string).