jquery - Converting JSON not returning Javascript array -


i have json returning server looks this

[{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"}] 

i handle using

var data =  json.parse(json); 

then, once doing this, call in loop

data.item(i); 

or using function data.splice(i, 1); giving me error

data.item not function

or

data.splice not function

i'm pretty because not true javascript array, haven't found has told me how convert one

edit looking .item() function used in nodelist (from things getelementbyclassname) however, not solve issue .splice

your json invalid - needs commas separating objects:

[{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"}] 

parse json were:

var data = json.parse(json); 

and access each object, use index of array:

var element1 = data[0]; // first element var element2 = data[1];  // second element 

etc.

and access values in objects:

var name1 = data[0].name1; // value1 

or even, since you've defined element1 variable:

var name1 = element1.name1; 

if you're using loop:

for (var = 0, l = arr.length; < l; i++) {   console.log(data[i]); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -