Currently, I am using an ajax query to read a local csv file and then loading the extracted values into an array.
This is how the string value appears in the csv file:
"Tiger","Architect","800","DRP","5421","VFX"
After loading this string into the array, it looks like this:
0: (6) ["Tiger", "Architect", "800", "DRP", "5421", "VFX"]
Now, my objective is to convert this aforementioned string into a JSON object structured as follows:
{
"data": [
{
"0": "Tiger",
"1": "Architect",
"2": "800",
"3": "DRP",
"4": "5421",
"5": "VFX"
}]
}
With all the values encapsulated within the data
object.
I attempted the following code for this purpose:
var arrayToString = JSON.stringify(Object.assign({}, data1));
var stringToJsonObject = JSON.parse(arrayToString);
The code successfully converts the array into JSON format, but with a length of 6
, whereas I require it to be 1
Is there any alternative method to achieve this?