Search object key name and use function












-2















I have an object which I am trying to push in an array



$scope.xslLetterSpacing = {
"_name": "letter-spacing",
"__prefix": "xsl",
"__text": "2pt"
};


So above the object which I am trying to push in another array:-



$scope.frontObjct = {
"stylesheet": {
"attribute-set": [{
"attribute": {
"_name": "text-align",
"__prefix": "xsl"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [{
"_name": "space-before",
"__prefix": "xsl"
},
{
"_name": "space-before.conditionality",
"__prefix": "xsl",
"__text": "retain"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "16pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "500"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "90%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__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"
}


}



So now what I am trying to do is to put condition. When _name": "letter-spacing" is not found in the attribute-set[1] , then push the xslLetterSpacing object in the attribute array and if the data object with _name": "letter-spacing" is already there in the Obj then do nothing.



I tried this to do with it is getting repeated with number of object already present in the array.



angular.forEach($scope.frontObjct.stylesheet["attribute-set"][1].attribute , function(value, key) {
if (key !== "_name") {
//pushing extra data to attribute field
$timeout(function(){
$scope.frontObjct.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
console.log($scope.frontObjct );
},500);
}
});


Where am I going wrong ?










share|improve this question

























  • 'attribute' is an array, don't you need to iterate through the array and test each object in the array?

    – SPlatten
    Nov 21 '18 at 10:12











  • @SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

    – WhoAmI
    Nov 21 '18 at 10:19








  • 1





    There is no JSON in this question. Those are javascript objects, JSON is a string notation

    – Liam
    Nov 21 '18 at 10:19











  • @Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

    – WhoAmI
    Nov 21 '18 at 10:21











  • No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

    – Liam
    Nov 21 '18 at 10:22


















-2















I have an object which I am trying to push in an array



$scope.xslLetterSpacing = {
"_name": "letter-spacing",
"__prefix": "xsl",
"__text": "2pt"
};


So above the object which I am trying to push in another array:-



$scope.frontObjct = {
"stylesheet": {
"attribute-set": [{
"attribute": {
"_name": "text-align",
"__prefix": "xsl"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [{
"_name": "space-before",
"__prefix": "xsl"
},
{
"_name": "space-before.conditionality",
"__prefix": "xsl",
"__text": "retain"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "16pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "500"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "90%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__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"
}


}



So now what I am trying to do is to put condition. When _name": "letter-spacing" is not found in the attribute-set[1] , then push the xslLetterSpacing object in the attribute array and if the data object with _name": "letter-spacing" is already there in the Obj then do nothing.



I tried this to do with it is getting repeated with number of object already present in the array.



angular.forEach($scope.frontObjct.stylesheet["attribute-set"][1].attribute , function(value, key) {
if (key !== "_name") {
//pushing extra data to attribute field
$timeout(function(){
$scope.frontObjct.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
console.log($scope.frontObjct );
},500);
}
});


Where am I going wrong ?










share|improve this question

























  • 'attribute' is an array, don't you need to iterate through the array and test each object in the array?

    – SPlatten
    Nov 21 '18 at 10:12











  • @SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

    – WhoAmI
    Nov 21 '18 at 10:19








  • 1





    There is no JSON in this question. Those are javascript objects, JSON is a string notation

    – Liam
    Nov 21 '18 at 10:19











  • @Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

    – WhoAmI
    Nov 21 '18 at 10:21











  • No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

    – Liam
    Nov 21 '18 at 10:22
















-2












-2








-2








I have an object which I am trying to push in an array



$scope.xslLetterSpacing = {
"_name": "letter-spacing",
"__prefix": "xsl",
"__text": "2pt"
};


So above the object which I am trying to push in another array:-



$scope.frontObjct = {
"stylesheet": {
"attribute-set": [{
"attribute": {
"_name": "text-align",
"__prefix": "xsl"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [{
"_name": "space-before",
"__prefix": "xsl"
},
{
"_name": "space-before.conditionality",
"__prefix": "xsl",
"__text": "retain"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "16pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "500"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "90%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__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"
}


}



So now what I am trying to do is to put condition. When _name": "letter-spacing" is not found in the attribute-set[1] , then push the xslLetterSpacing object in the attribute array and if the data object with _name": "letter-spacing" is already there in the Obj then do nothing.



I tried this to do with it is getting repeated with number of object already present in the array.



angular.forEach($scope.frontObjct.stylesheet["attribute-set"][1].attribute , function(value, key) {
if (key !== "_name") {
//pushing extra data to attribute field
$timeout(function(){
$scope.frontObjct.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
console.log($scope.frontObjct );
},500);
}
});


Where am I going wrong ?










share|improve this question
















I have an object which I am trying to push in an array



$scope.xslLetterSpacing = {
"_name": "letter-spacing",
"__prefix": "xsl",
"__text": "2pt"
};


So above the object which I am trying to push in another array:-



$scope.frontObjct = {
"stylesheet": {
"attribute-set": [{
"attribute": {
"_name": "text-align",
"__prefix": "xsl"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [{
"_name": "space-before",
"__prefix": "xsl"
},
{
"_name": "space-before.conditionality",
"__prefix": "xsl",
"__text": "retain"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "16pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "500"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "90%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__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"
}


}



So now what I am trying to do is to put condition. When _name": "letter-spacing" is not found in the attribute-set[1] , then push the xslLetterSpacing object in the attribute array and if the data object with _name": "letter-spacing" is already there in the Obj then do nothing.



I tried this to do with it is getting repeated with number of object already present in the array.



angular.forEach($scope.frontObjct.stylesheet["attribute-set"][1].attribute , function(value, key) {
if (key !== "_name") {
//pushing extra data to attribute field
$timeout(function(){
$scope.frontObjct.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
console.log($scope.frontObjct );
},500);
}
});


Where am I going wrong ?







javascript arrays angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:28







WhoAmI

















asked Nov 21 '18 at 10:09









WhoAmIWhoAmI

13211




13211













  • 'attribute' is an array, don't you need to iterate through the array and test each object in the array?

    – SPlatten
    Nov 21 '18 at 10:12











  • @SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

    – WhoAmI
    Nov 21 '18 at 10:19








  • 1





    There is no JSON in this question. Those are javascript objects, JSON is a string notation

    – Liam
    Nov 21 '18 at 10:19











  • @Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

    – WhoAmI
    Nov 21 '18 at 10:21











  • No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

    – Liam
    Nov 21 '18 at 10:22





















  • 'attribute' is an array, don't you need to iterate through the array and test each object in the array?

    – SPlatten
    Nov 21 '18 at 10:12











  • @SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

    – WhoAmI
    Nov 21 '18 at 10:19








  • 1





    There is no JSON in this question. Those are javascript objects, JSON is a string notation

    – Liam
    Nov 21 '18 at 10:19











  • @Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

    – WhoAmI
    Nov 21 '18 at 10:21











  • No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

    – Liam
    Nov 21 '18 at 10:22



















'attribute' is an array, don't you need to iterate through the array and test each object in the array?

– SPlatten
Nov 21 '18 at 10:12





'attribute' is an array, don't you need to iterate through the array and test each object in the array?

– SPlatten
Nov 21 '18 at 10:12













@SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

– WhoAmI
Nov 21 '18 at 10:19







@SPlatten Yes I need to match each and every object's _name in the array but I am not getting how.

– WhoAmI
Nov 21 '18 at 10:19






1




1





There is no JSON in this question. Those are javascript objects, JSON is a string notation

– Liam
Nov 21 '18 at 10:19





There is no JSON in this question. Those are javascript objects, JSON is a string notation

– Liam
Nov 21 '18 at 10:19













@Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

– WhoAmI
Nov 21 '18 at 10:21





@Liam I am pretty sure those JSON are defined in javascript objects. Isn't it ?

– WhoAmI
Nov 21 '18 at 10:21













No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

– Liam
Nov 21 '18 at 10:22







No your wrong, JSON is a string i.e. "{"a":"test"}" a Javascript object is an object, i.e. {a:"test"}

– Liam
Nov 21 '18 at 10:22














1 Answer
1






active

oldest

votes


















2














You can do like this



var itemLetterSpacing = $scope.Obj.stylesheet["attribute-set"][1].attribute.filter(function(item) {
return item._name === "letter-spacing";
})[0];

if(!itemLetterSpacing) {
$scope.Obj.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
}
console.log($scope.Obj);





share|improve this answer


























  • I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

    – WhoAmI
    Nov 21 '18 at 10:46













  • copy now and try

    – Kipl Developer
    Nov 21 '18 at 10:52






  • 1





    Thanks , This is exactly I was looking for.

    – WhoAmI
    Nov 21 '18 at 11:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409651%2fsearch-object-key-name-and-use-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can do like this



var itemLetterSpacing = $scope.Obj.stylesheet["attribute-set"][1].attribute.filter(function(item) {
return item._name === "letter-spacing";
})[0];

if(!itemLetterSpacing) {
$scope.Obj.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
}
console.log($scope.Obj);





share|improve this answer


























  • I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

    – WhoAmI
    Nov 21 '18 at 10:46













  • copy now and try

    – Kipl Developer
    Nov 21 '18 at 10:52






  • 1





    Thanks , This is exactly I was looking for.

    – WhoAmI
    Nov 21 '18 at 11:01
















2














You can do like this



var itemLetterSpacing = $scope.Obj.stylesheet["attribute-set"][1].attribute.filter(function(item) {
return item._name === "letter-spacing";
})[0];

if(!itemLetterSpacing) {
$scope.Obj.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
}
console.log($scope.Obj);





share|improve this answer


























  • I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

    – WhoAmI
    Nov 21 '18 at 10:46













  • copy now and try

    – Kipl Developer
    Nov 21 '18 at 10:52






  • 1





    Thanks , This is exactly I was looking for.

    – WhoAmI
    Nov 21 '18 at 11:01














2












2








2







You can do like this



var itemLetterSpacing = $scope.Obj.stylesheet["attribute-set"][1].attribute.filter(function(item) {
return item._name === "letter-spacing";
})[0];

if(!itemLetterSpacing) {
$scope.Obj.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
}
console.log($scope.Obj);





share|improve this answer















You can do like this



var itemLetterSpacing = $scope.Obj.stylesheet["attribute-set"][1].attribute.filter(function(item) {
return item._name === "letter-spacing";
})[0];

if(!itemLetterSpacing) {
$scope.Obj.stylesheet["attribute-set"][1].attribute.push($scope.xslLetterSpacing);
}
console.log($scope.Obj);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 10:51

























answered Nov 21 '18 at 10:39









Kipl DeveloperKipl Developer

513




513













  • I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

    – WhoAmI
    Nov 21 '18 at 10:46













  • copy now and try

    – Kipl Developer
    Nov 21 '18 at 10:52






  • 1





    Thanks , This is exactly I was looking for.

    – WhoAmI
    Nov 21 '18 at 11:01



















  • I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

    – WhoAmI
    Nov 21 '18 at 10:46













  • copy now and try

    – Kipl Developer
    Nov 21 '18 at 10:52






  • 1





    Thanks , This is exactly I was looking for.

    – WhoAmI
    Nov 21 '18 at 11:01

















I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

– WhoAmI
Nov 21 '18 at 10:46







I am getting error angular.js:13424 Error: [ng:areq] Argument controller is not a function

– WhoAmI
Nov 21 '18 at 10:46















copy now and try

– Kipl Developer
Nov 21 '18 at 10:52





copy now and try

– Kipl Developer
Nov 21 '18 at 10:52




1




1





Thanks , This is exactly I was looking for.

– WhoAmI
Nov 21 '18 at 11:01





Thanks , This is exactly I was looking for.

– WhoAmI
Nov 21 '18 at 11:01




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409651%2fsearch-object-key-name-and-use-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)