javascript - How to convert Array into json object? -
this question has answer here:
- convert array object 31 answers
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
Post a Comment