I have an Array var category:
var category = ["all", "Items Id", "Items Sku", "Items Name"]
I need to convert it to a JSON object in the following format:
var category = [{
"id": "all",
"text": "all",
"children": [{
"id": "Items Id",
"text": "Item Id"
}, {
"id": "Items Sku",
"text": "Items Sku"
}, {
"id": "Items Name",
"text": "Items Name"
}]
}, ];
I'm trying to work with the code below but doesn't work:
var category = ["all", "Items Id", "Items Sku", "Items Name"]
var json = header.map((str, index) => ({ text: str, id: index + 1 }));
var categorylist = [];
for (var i in json) {
categories.push({
"id": json[0].value,
"text": json[0].value,
"children": [{
id: json[i].value,
text: json[i].value
}]
}
console.log(categorylist)
Any help?