this first question here.
i have ajax returning json string, , after function.done, going through:
var ardata = []; $.each(response, function(key, value) { var temp = [value[0], value[1]]; ardata.push(temp); //console.log(temp); }); console.log(ardata);
when print var temp, result quite normal, ["buffer stok", 497206627]. but, when printout ardata variable, resulting console log follows:
how that series of 2 dimensional arrays shows 4 in length, element 0, 1, , 3?
edit: log of response object: resulting response log
*****update*****
i'm trying re-word question. i'm using ajax json data, in pairs: [["data 1", int value 1],["data 2", int value 2],...]. data, intend create javascript array same value, using ardata.push(["data 1", int value 1]);, each pair of json data.
this original code:
var ardata = []; $.ajax({ cache: false, type: 'get', url: 'dtsearch4.php', data: {type : 2}, datatype: 'json', async: false }) .done(function(response){ $.each(response, function(key, value) { $.each(v,function(key, value){ //var temp = [value[0], value[1]]; ardata.push([value[0], value[1]]); }); });
however, resulting array this:
v[array[2], array[2],[array[2],...] v0: array[4] 0: "apbd-i" 1: 302462864 3: nan length: 4 __proto__: array[0] v1: array[4] v2: array[4]
=> what's array[4], , element number 0, 1 , 3? no number 2?
while want array 2 elements:
v[array[2], array[2],[array[2],...] v0: array[2] 0: "apbd-i" 1: 302462864 length: 2 __proto__: array[0] v1: array[2] v2: array[2]
you have run each loop 2 times.
$.each(v, function(v_key, v_value) { $.each(v_key,function(key, value){ ardata.push([value[0], value[1]]); }); }); 1st loop take values v0, v1, v2. second loop take values of v0 0,1,3,length,__proto__
Comments
Post a Comment