I'm trying to add 2 values to an array that I extract from a html page. However, the value for key [0] always returns undefined whereas I expect 4 in this case.
<script type="text/javascript">
$(document).ready(function ()
{
var arrayList = $("some class");
var x = new Array();
var j = 0;
var k = 1;
$.each(arrayList, function(i,e) {
var MyIf = $(e).text();
x[j] = new Array();
if(k == 2) {
x[j][0] = 4; // This always returns undefined, no matter which value I assign.
}
if(k == 3) {
x[j][1] = parseInt(MyIf);
}
if(k % 3 == 0) {
j++;
k = 1;
} else {
k++;
}
});
console.log(x); // the console returns for all [0] "undefined"
});
</script>
What am I missing?
arrayListhave? If it has only 1, I would expectxto be empty since you only add to it whenk == 2ork == 3. In other words, how many times does your$.eachloop run?