How to convert Array into json object?

Shrinivas Pai

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"
}
Nikhil Aggarwal

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert array to a json object?

How to convert an array of JSON into an array of javascript object?

How to convert JSON array to OBJECT array javascript?

How to convert json Object to json Array?

How to Convert Json Object to Array in C#

How to convert JSON object to an Typescript array in an api

How to convert JSON object to JavaScript array?

How to convert a JSON object stream into an array with jq

How to convert JSON object to an Typescript array?

How to Convert nested json to array of object in Javascript?

How to convert json to array object in javascript?

How to convert JSON Object into Javascript array

how to convert this JavaScript object that contains an array to JSON?

How to convert JSON object into an array in React Native

How to convert array of strings into JSON object?

How to Convert String Array JSON in a Java Object

How to convert json object to string array

React: How to convert JSON Object to Array and render it?

How convert JSON array or JSON object to list of object?

Convert object to JSON Array?

Convert Json object to an array

how to Convert JavaScript array (without object name) into json (with object name)?

GSON. How to convert json object to json array?

How can I convert to Json Object to Json Array in Karate?

How do I convert an Array with a JSON string into a JSON object (ruby)

How to convert json array to json object in lambda python function

How to convert the given dictionary into a JSON Object containing a JSON Array In Swift?

How to convert a Json object with multiple objects in it (legacy) to a Json array

How to convert JSON object rows into JSON array in MySQL?