As a newcomer to javascript and angular, I am facing a challenge. I have a JSON object like this: {"xyz":{Key:info}}
. My goal is to add {Key:info}
into an array.
Specifically, I want to transform "xyz" into an array format. For example: {"xyz":[{Key:info}]}
This way, I can easily push multiple instances of {Key:info}
into that array - like this:
{"xyz":[{Key:info},{Key:info},{Key:info}]}
.
In addition, I need to ensure that if xyz is originally an object, it gets converted into an array and only one instance is pushed in.
My struggle lies in figuring out how to accomplish this using angular javascript.
EDIT :- Added original JSON
$scope.ContentObj= {
"attribute-set": [
{
"attribute": [
{
"_name": "text-align",
"__prefix": "xsl",
"__text": "end"
},
{
"_name": "end-indent",
"__prefix": "xsl",
"__text": "10pt"
}
],
"_name": "odd__header",
"__prefix": "xsl"
},
{
"attribute": {
"_name": "font-weight",
"__prefix": "xsl",
"__text": "bold"
},
"_name": "pagenum",
"__prefix": "xsl"
}
],
"_version": "2.0",
"__prefix": "xsl"
}