var dataArray = [];
dataArray.push({ items: [] });
var items = $('#services_hidden').val();
var itemsArray = items.split(",");
console.log("itemsArray: " + itemsArray);
$.each( itemsArray, function( index, value ){
dataArray[0].items.push(value);
});
console.log("dataArray " + JSON.stringify(dataArray));
This way I want to save data in an array reading an input value that like this:
<input id="services_hidden" value="item1,value1,item2,value2,item3,value3" />
So there can be multiple items assigned to a specific value. At the moment it looks like this which is wrong because it's all saved into items not seperated from each other:
dataArray [{"items":["item1","value1","item2,"value2"]}]
But I want this (I hope I show this correctly):
dataArray [{"items":{"item1:value1"},{"item2:value2"}}]
So the parent is items and every two values in #services_hidden.val() seperated by a comma should create an key:value pair.
What do I have to change in my code to achieve this?