Dynamically I am getting an array
.
For example we can consider this following array
.
var sampleArray=[
"logo",
"Details",
"titles"
];
But I want it something like this.
jsonObj={
"poistion1":"logo",
"poistion2":"Details",
"poistion3":"titles"
}
You can iterate on array and create object like following
var jsonObj = {};
for (var i = 0 ; i < sampleArray.length; i++) {
jsonObj["position" + (i+1)] = sampleArray[i];
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments