How to find the value of the array object after push in Angular2












1














I have an array defined in angular2 .ts file as -



this.dropdownValue=;


And then i push values into them from different functions like -



 this.dropdownValue.push({ item_text: this.organizationInfo.records[i]._fields[0].end.properties.name });

this.dropdownValue.push({ item_text: this.departmentInfo.records[i]._fields[0].end.properties.name });


The Console statements -



console.log("inside Proceed, this.dropdownValue =", typeof(this.dropdownValue));

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue[0]);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue.length);


There Outputs of a few values are -



 typeOf(this.dropdownValue ) = object

this.dropdownValue =
[
0:{item_text: "IT"}
1:{item_text: "post"}
2:{item_text: "intimationDate"}
3:{item_text: "lossDescription"}
]

this.dropdownValue[0] = undefined

this.dropdownValue.length = 0


I want to access the values of -



  item_text 


.i.e store it in another variable/array.



And i am unable to do so.Neither am i able to access these values, no find its length nor find the value at a particular length
PLease help










share|improve this question
























  • What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
    – xyz
    Nov 19 '18 at 15:20






  • 1




    this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – xyz
    Nov 19 '18 at 15:21












  • Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
    – Techdive
    Nov 19 '18 at 17:44










  • If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
    – xyz
    Nov 19 '18 at 17:49










  • And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
    – xyz
    Nov 19 '18 at 17:51
















1














I have an array defined in angular2 .ts file as -



this.dropdownValue=;


And then i push values into them from different functions like -



 this.dropdownValue.push({ item_text: this.organizationInfo.records[i]._fields[0].end.properties.name });

this.dropdownValue.push({ item_text: this.departmentInfo.records[i]._fields[0].end.properties.name });


The Console statements -



console.log("inside Proceed, this.dropdownValue =", typeof(this.dropdownValue));

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue[0]);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue.length);


There Outputs of a few values are -



 typeOf(this.dropdownValue ) = object

this.dropdownValue =
[
0:{item_text: "IT"}
1:{item_text: "post"}
2:{item_text: "intimationDate"}
3:{item_text: "lossDescription"}
]

this.dropdownValue[0] = undefined

this.dropdownValue.length = 0


I want to access the values of -



  item_text 


.i.e store it in another variable/array.



And i am unable to do so.Neither am i able to access these values, no find its length nor find the value at a particular length
PLease help










share|improve this question
























  • What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
    – xyz
    Nov 19 '18 at 15:20






  • 1




    this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – xyz
    Nov 19 '18 at 15:21












  • Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
    – Techdive
    Nov 19 '18 at 17:44










  • If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
    – xyz
    Nov 19 '18 at 17:49










  • And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
    – xyz
    Nov 19 '18 at 17:51














1












1








1







I have an array defined in angular2 .ts file as -



this.dropdownValue=;


And then i push values into them from different functions like -



 this.dropdownValue.push({ item_text: this.organizationInfo.records[i]._fields[0].end.properties.name });

this.dropdownValue.push({ item_text: this.departmentInfo.records[i]._fields[0].end.properties.name });


The Console statements -



console.log("inside Proceed, this.dropdownValue =", typeof(this.dropdownValue));

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue[0]);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue.length);


There Outputs of a few values are -



 typeOf(this.dropdownValue ) = object

this.dropdownValue =
[
0:{item_text: "IT"}
1:{item_text: "post"}
2:{item_text: "intimationDate"}
3:{item_text: "lossDescription"}
]

this.dropdownValue[0] = undefined

this.dropdownValue.length = 0


I want to access the values of -



  item_text 


.i.e store it in another variable/array.



And i am unable to do so.Neither am i able to access these values, no find its length nor find the value at a particular length
PLease help










share|improve this question















I have an array defined in angular2 .ts file as -



this.dropdownValue=;


And then i push values into them from different functions like -



 this.dropdownValue.push({ item_text: this.organizationInfo.records[i]._fields[0].end.properties.name });

this.dropdownValue.push({ item_text: this.departmentInfo.records[i]._fields[0].end.properties.name });


The Console statements -



console.log("inside Proceed, this.dropdownValue =", typeof(this.dropdownValue));

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue[0]);

console.log("inside Proceed, this.dropdownValue =", this.dropdownValue.length);


There Outputs of a few values are -



 typeOf(this.dropdownValue ) = object

this.dropdownValue =
[
0:{item_text: "IT"}
1:{item_text: "post"}
2:{item_text: "intimationDate"}
3:{item_text: "lossDescription"}
]

this.dropdownValue[0] = undefined

this.dropdownValue.length = 0


I want to access the values of -



  item_text 


.i.e store it in another variable/array.



And i am unable to do so.Neither am i able to access these values, no find its length nor find the value at a particular length
PLease help







arrays angular object






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 17:52

























asked Nov 19 '18 at 15:16









Techdive

21216




21216












  • What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
    – xyz
    Nov 19 '18 at 15:20






  • 1




    this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – xyz
    Nov 19 '18 at 15:21












  • Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
    – Techdive
    Nov 19 '18 at 17:44










  • If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
    – xyz
    Nov 19 '18 at 17:49










  • And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
    – xyz
    Nov 19 '18 at 17:51


















  • What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
    – xyz
    Nov 19 '18 at 15:20






  • 1




    this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – xyz
    Nov 19 '18 at 15:21












  • Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
    – Techdive
    Nov 19 '18 at 17:44










  • If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
    – xyz
    Nov 19 '18 at 17:49










  • And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
    – xyz
    Nov 19 '18 at 17:51
















What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
– xyz
Nov 19 '18 at 15:20




What is this.dropdownValue[0] = undefined and this.dropdownValue.length = 0? its your output or are you assigning these values?
– xyz
Nov 19 '18 at 15:20




1




1




this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– xyz
Nov 19 '18 at 15:21






this.dropdownValue.find((elem) => elem.item_text === "IT") should work in case the texts are unique, developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– xyz
Nov 19 '18 at 15:21














Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
– Techdive
Nov 19 '18 at 17:44




Hi Ashish, Thanks. this.dropdownValue[0] = undefined and this.dropdownValue.length = 0 are the outputs. And i don't wanna hardcode it. Like - you did --> === "IT". I want to place the entire item_text values into a variable
– Techdive
Nov 19 '18 at 17:44












If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
– xyz
Nov 19 '18 at 17:49




If those are the outputs, then it seems you are accessing the array before it is populated? maybe outside some subscription, while the array under subscription. Is it getting populated throughsome async request?
– xyz
Nov 19 '18 at 17:49












And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
– xyz
Nov 19 '18 at 17:51




And you want to store in a variable? How many variables will you make then? Another variable which is an array containg the item_text would be better in that case then
– xyz
Nov 19 '18 at 17:51












1 Answer
1






active

oldest

votes


















0














let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');


I edit my answer because I undestood right now what you are looking for.



let otherArray = ; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}


I know that is not the best way to do, but when i have to do something similar, i always do that






share|improve this answer























  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
    – Nic3500
    Nov 19 '18 at 17:43










  • Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
    – Techdive
    Nov 19 '18 at 17:57











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%2f53377610%2fhow-to-find-the-value-of-the-array-object-after-push-in-angular2%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









0














let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');


I edit my answer because I undestood right now what you are looking for.



let otherArray = ; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}


I know that is not the best way to do, but when i have to do something similar, i always do that






share|improve this answer























  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
    – Nic3500
    Nov 19 '18 at 17:43










  • Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
    – Techdive
    Nov 19 '18 at 17:57
















0














let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');


I edit my answer because I undestood right now what you are looking for.



let otherArray = ; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}


I know that is not the best way to do, but when i have to do something similar, i always do that






share|improve this answer























  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
    – Nic3500
    Nov 19 '18 at 17:43










  • Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
    – Techdive
    Nov 19 '18 at 17:57














0












0








0






let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');


I edit my answer because I undestood right now what you are looking for.



let otherArray = ; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}


I know that is not the best way to do, but when i have to do something similar, i always do that






share|improve this answer














let otherVariable = this.dropdownValue.find(x => x.item_text === 'IT');


I edit my answer because I undestood right now what you are looking for.



let otherArray = ; 
for (let obj of this.dropdownValue) {
otherArray.push(obj.item_text);
}


I know that is not the best way to do, but when i have to do something similar, i always do that







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 20:48

























answered Nov 19 '18 at 15:57









Mati Cassanelli

12




12












  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
    – Nic3500
    Nov 19 '18 at 17:43










  • Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
    – Techdive
    Nov 19 '18 at 17:57


















  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
    – Nic3500
    Nov 19 '18 at 17:43










  • Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
    – Techdive
    Nov 19 '18 at 17:57
















While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
– Nic3500
Nov 19 '18 at 17:43




While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
– Nic3500
Nov 19 '18 at 17:43












Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
– Techdive
Nov 19 '18 at 17:57




Hey Matias, thanks for the reply. I corrected my question. I want to accumulate all item_text from the array.
– Techdive
Nov 19 '18 at 17:57


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53377610%2fhow-to-find-the-value-of-the-array-object-after-push-in-angular2%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith