javascript - How to convert Array into json object? -


this question has answer here:

dynamically getting array.

for example can consider following array.

var samplearray=[         "logo",         "details",         "titles"     ]; 

but want this.

jsonobj={ "poistion1":"logo", "poistion2":"details", "poistion3":"titles" } 

you can iterate on array , create object following

var jsonobj = {}; (var = 0 ; < samplearray.length; i++) {     jsonobj["position" + (i+1)] = samplearray[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 -