I am trying to check and push object in an object details from a JSON.
This is how my JSON look like
{
"stylesheet": {
"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"
}
],
"_xmlns:xsl": "http://www.w3.org/1999/XSL/Transform",
"_xmlns:fo": "http://www.w3.org/1999/XSL/Format",
"_version": "2.0",
"__prefix": "xsl"
}
}
Now , I am trying to read the attribute-set value [1] ie; "pagenum" . HEre I am trying to check for more attribute value with name. If not present push it into that attribute set.
I don't have any problem in pushing into attribute-set[0] as it is in array . Here I got single object in attribute-set[1].
Tried this for attr-set[1], but throwing error - Uncaught TypeError: $scope.contentObj.stylesheet.attribute-set[1].attribute.some is not a function
//for checking font name
var checkcontentPageFont = obj => obj._name === 'font-family';
// check font family
var checkcontentPageFont_available = $scope.contentObj.stylesheet["attribute-set"][1].attribute.some(checkcontentPageFont);
if(checkcontentPageFont_available === true ){
}
else{
$scope.contentObj.stylesheet["attribute-set"][1].attribute.push({
"_name": "font-family",
"__prefix": "xsl",
"__text": "sans"
}
);
}
I can successfully implementing the above code if there is an array like attribute-set[0]. How can I check this for single object. If not found push and an array will be created on attribute-set[1] ?