I am attempting to populate an array with objects in order to achieve the following structure:
myobject1: Object:
ItemInside: Object
myobject2: Object
ItemInside: Object
myobject3: Object
ItemInside: Object
myobject4: Object
ItemInside: Object
However, the objects are currently being added in a different structure:
0: Object
myobject1: Object
ItemInside: Object
1: Object
myobject2: Object
ItemInside: Object
2: Object
myobject3: Object
ItemInside: Object
3: Object
myobject4: Object
ItemInside: Object
The code used for populating the second array is as follows:
var myarr = [];
$.each(returnedData, function (index, value) {
var field = {};
field[value.Name] = {
display: value.DisplayName,
cssClass: value.FieldType,
};
myarr.push(field);
});
Although my array contains all the necessary information without errors, it is structured incorrectly.
An example of the current structure can be seen here:
In essence, I am simply trying to add the "myobjects" to the parent object, but they are instead being added as their own parents. How can I modify the code to achieve the desired structure?