combining javascript object property value and display












0














Hi I am having difficulty in traversing in javascript object. How can I get scheme_name & NAV from both and store it in variable like "You have 2 schemes linked to your account. scheme_name1 NAV value is "" scheme_name2 NAV value is "" and so forth. Please explain it to me thanx



  let data = [{
"CustomerID": 12345,
"NAV": "95.24059718",
"cost_of_purchase": 799900,
"folio_number": 10007060,
"id": 1,
"mutual_fund_house": "AXIS MUTUAL FUND",
"no_of_units": 15000,
"option": "GROWTH",
"plan": "REGULAR",
"resource_uri": "/api/v1/folio/1/",
"scheme_name": "AXIS LONG TERM EQUITY",
"value_of_units": "1428608.9580"
}, {
"CustomerID": 12345,
"NAV": "1053.31517400",
"cost_of_purchase": 1500000,
"folio_number": 5540000567,
"id": 2,
"mutual_fund_house": "SBI Mutual Fund",
"no_of_units": 2750,
"option": "DIVIDEND",
"plan": "DIRECT",
"resource_uri": "/api/v1/folio/2/",
"scheme_name": "SBI Magnum Multicap Fund",
"value_of_units": "2896616.7270"
}]









share|improve this question






















  • data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
    – DontVoteMeDown
    Nov 19 '18 at 15:36








  • 1




    What have you tried so far? What array functions have you researched and tried?
    – wlh
    Nov 19 '18 at 15:36










  • @DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
    – wlh
    Nov 19 '18 at 15:37










  • Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
    – Pbd
    Nov 19 '18 at 15:38










  • @wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
    – DontVoteMeDown
    Nov 19 '18 at 15:44


















0














Hi I am having difficulty in traversing in javascript object. How can I get scheme_name & NAV from both and store it in variable like "You have 2 schemes linked to your account. scheme_name1 NAV value is "" scheme_name2 NAV value is "" and so forth. Please explain it to me thanx



  let data = [{
"CustomerID": 12345,
"NAV": "95.24059718",
"cost_of_purchase": 799900,
"folio_number": 10007060,
"id": 1,
"mutual_fund_house": "AXIS MUTUAL FUND",
"no_of_units": 15000,
"option": "GROWTH",
"plan": "REGULAR",
"resource_uri": "/api/v1/folio/1/",
"scheme_name": "AXIS LONG TERM EQUITY",
"value_of_units": "1428608.9580"
}, {
"CustomerID": 12345,
"NAV": "1053.31517400",
"cost_of_purchase": 1500000,
"folio_number": 5540000567,
"id": 2,
"mutual_fund_house": "SBI Mutual Fund",
"no_of_units": 2750,
"option": "DIVIDEND",
"plan": "DIRECT",
"resource_uri": "/api/v1/folio/2/",
"scheme_name": "SBI Magnum Multicap Fund",
"value_of_units": "2896616.7270"
}]









share|improve this question






















  • data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
    – DontVoteMeDown
    Nov 19 '18 at 15:36








  • 1




    What have you tried so far? What array functions have you researched and tried?
    – wlh
    Nov 19 '18 at 15:36










  • @DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
    – wlh
    Nov 19 '18 at 15:37










  • Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
    – Pbd
    Nov 19 '18 at 15:38










  • @wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
    – DontVoteMeDown
    Nov 19 '18 at 15:44
















0












0








0







Hi I am having difficulty in traversing in javascript object. How can I get scheme_name & NAV from both and store it in variable like "You have 2 schemes linked to your account. scheme_name1 NAV value is "" scheme_name2 NAV value is "" and so forth. Please explain it to me thanx



  let data = [{
"CustomerID": 12345,
"NAV": "95.24059718",
"cost_of_purchase": 799900,
"folio_number": 10007060,
"id": 1,
"mutual_fund_house": "AXIS MUTUAL FUND",
"no_of_units": 15000,
"option": "GROWTH",
"plan": "REGULAR",
"resource_uri": "/api/v1/folio/1/",
"scheme_name": "AXIS LONG TERM EQUITY",
"value_of_units": "1428608.9580"
}, {
"CustomerID": 12345,
"NAV": "1053.31517400",
"cost_of_purchase": 1500000,
"folio_number": 5540000567,
"id": 2,
"mutual_fund_house": "SBI Mutual Fund",
"no_of_units": 2750,
"option": "DIVIDEND",
"plan": "DIRECT",
"resource_uri": "/api/v1/folio/2/",
"scheme_name": "SBI Magnum Multicap Fund",
"value_of_units": "2896616.7270"
}]









share|improve this question













Hi I am having difficulty in traversing in javascript object. How can I get scheme_name & NAV from both and store it in variable like "You have 2 schemes linked to your account. scheme_name1 NAV value is "" scheme_name2 NAV value is "" and so forth. Please explain it to me thanx



  let data = [{
"CustomerID": 12345,
"NAV": "95.24059718",
"cost_of_purchase": 799900,
"folio_number": 10007060,
"id": 1,
"mutual_fund_house": "AXIS MUTUAL FUND",
"no_of_units": 15000,
"option": "GROWTH",
"plan": "REGULAR",
"resource_uri": "/api/v1/folio/1/",
"scheme_name": "AXIS LONG TERM EQUITY",
"value_of_units": "1428608.9580"
}, {
"CustomerID": 12345,
"NAV": "1053.31517400",
"cost_of_purchase": 1500000,
"folio_number": 5540000567,
"id": 2,
"mutual_fund_house": "SBI Mutual Fund",
"no_of_units": 2750,
"option": "DIVIDEND",
"plan": "DIRECT",
"resource_uri": "/api/v1/folio/2/",
"scheme_name": "SBI Magnum Multicap Fund",
"value_of_units": "2896616.7270"
}]






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 15:31









Meet Singh

11




11












  • data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
    – DontVoteMeDown
    Nov 19 '18 at 15:36








  • 1




    What have you tried so far? What array functions have you researched and tried?
    – wlh
    Nov 19 '18 at 15:36










  • @DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
    – wlh
    Nov 19 '18 at 15:37










  • Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
    – Pbd
    Nov 19 '18 at 15:38










  • @wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
    – DontVoteMeDown
    Nov 19 '18 at 15:44




















  • data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
    – DontVoteMeDown
    Nov 19 '18 at 15:36








  • 1




    What have you tried so far? What array functions have you researched and tried?
    – wlh
    Nov 19 '18 at 15:36










  • @DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
    – wlh
    Nov 19 '18 at 15:37










  • Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
    – Pbd
    Nov 19 '18 at 15:38










  • @wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
    – DontVoteMeDown
    Nov 19 '18 at 15:44


















data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
– DontVoteMeDown
Nov 19 '18 at 15:36






data.forEach(item => console.log(`Schema ${item.scheme_name} value is ${item.NAV}`));
– DontVoteMeDown
Nov 19 '18 at 15:36






1




1




What have you tried so far? What array functions have you researched and tried?
– wlh
Nov 19 '18 at 15:36




What have you tried so far? What array functions have you researched and tried?
– wlh
Nov 19 '18 at 15:36












@DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
– wlh
Nov 19 '18 at 15:37




@DontVoteMeDown Don't just give an answer to a question like this. What does Sumit learn from your answer except this specific answer in this specific instance? He needs to do some research.
– wlh
Nov 19 '18 at 15:37












Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
– Pbd
Nov 19 '18 at 15:38




Your data object is an array of Objects. You can use forEach() --> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… to accomplish your task. Also your question doesn't meet SOF standards.
– Pbd
Nov 19 '18 at 15:38












@wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
– DontVoteMeDown
Nov 19 '18 at 15:44






@wlh what he will learn or not is up to him. He can search over what I have suggested and learn a lot, or just copy-paste it in his code, as much of developers do. If he wants to copy-paste he will anyway, with or without any help, it is not my fault.
– DontVoteMeDown
Nov 19 '18 at 15:44














4 Answers
4






active

oldest

votes


















0














It looks like you try to map that object to another object.



First, try to read and understand array methods, you can check:



https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array



And for map method you can check:



https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map



And as a specific answer you can do:



const mappedData = data.map(function(item) {
return {
scheme_name: item.scheme_name,
NAV: item.NAV
};
});


This will return you an array of a simplified version of yours.



After that, you can convert it to a string like:



let solution = `You have ${mappedData.length} schemes linked to your account. `;
mappedData.forEach(function(mapped) {
solution += mapped.scheme_name + ' is ' + mapped.NAV + ' '
});


Note: I showed map method for giving an insight about what you can do, normally you don't need to simplify, you can directly use for each version.






share|improve this answer





























    0














    Imagine each one of your objects (in this case you have provided two (2)) as an associative array inside of an array. Meaning that rather than reference it by it's index position, you can reference it by it's key.



    This means to access object 1, you would have to write data[0]. But if you alerted this, this would simply tell you that data[0] is an object. Which is is.



    To access an actual value in that array, you would then have to provide the key, which you can do by providing a number, or in your case perhaps more easily, it's associated key, which is "scheme_name".



    See the following :






    let data = [{
    "CustomerID": 12345,
    "NAV": "95.24059718",
    "cost_of_purchase": 799900,
    "folio_number": 10007060,
    "id": 1,
    "mutual_fund_house": "AXIS MUTUAL FUND",
    "no_of_units": 15000,
    "option": "GROWTH",
    "plan": "REGULAR",
    "resource_uri": "/api/v1/folio/1/",
    "scheme_name": "AXIS LONG TERM EQUITY",
    "value_of_units": "1428608.9580"
    }, {
    "CustomerID": 12345,
    "NAV": "1053.31517400",
    "cost_of_purchase": 1500000,
    "folio_number": 5540000567,
    "id": 2,
    "mutual_fund_house": "SBI Mutual Fund",
    "no_of_units": 2750,
    "option": "DIVIDEND",
    "plan": "DIRECT",
    "resource_uri": "/api/v1/folio/2/",
    "scheme_name": "SBI Magnum Multicap Fund",
    "value_of_units": "2896616.7270"
    }]

    for (let i = 0; i < data.length; i++) {
    alert(data[i]["scheme_name"]);
    }





    So quite simply, for i = 0, with i being less than the number of associative arrays in your array named data, alert the value on that indexed array, by the associated key.






    share|improve this answer





























      0














      You've got an array of data so firstly you need to iterate through that array.



      Pick which properties you want to keep per record, and save them to a results array.



      Once you have the results you can iterate through them and print out your individual records.






      let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

      let results =
      data.forEach(datum => {
      results.push({
      scheme_name: datum.scheme_name,
      nav: datum.NAV,
      })
      })

      console.log(`You've got ${results.length} items in your account.`)
      results.forEach(result => {
      console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
      })








      share|improve this answer































        -1














        I created sample fiddle for you. You need to iterate over each object in your main object and store all information outside.



        data.forEach(function(item) {
        console.log(item.scheme_name);
        });





        share|improve this answer





















          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%2f53377885%2fcombining-javascript-object-property-value-and-display%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It looks like you try to map that object to another object.



          First, try to read and understand array methods, you can check:



          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array



          And for map method you can check:



          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map



          And as a specific answer you can do:



          const mappedData = data.map(function(item) {
          return {
          scheme_name: item.scheme_name,
          NAV: item.NAV
          };
          });


          This will return you an array of a simplified version of yours.



          After that, you can convert it to a string like:



          let solution = `You have ${mappedData.length} schemes linked to your account. `;
          mappedData.forEach(function(mapped) {
          solution += mapped.scheme_name + ' is ' + mapped.NAV + ' '
          });


          Note: I showed map method for giving an insight about what you can do, normally you don't need to simplify, you can directly use for each version.






          share|improve this answer


























            0














            It looks like you try to map that object to another object.



            First, try to read and understand array methods, you can check:



            https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array



            And for map method you can check:



            https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map



            And as a specific answer you can do:



            const mappedData = data.map(function(item) {
            return {
            scheme_name: item.scheme_name,
            NAV: item.NAV
            };
            });


            This will return you an array of a simplified version of yours.



            After that, you can convert it to a string like:



            let solution = `You have ${mappedData.length} schemes linked to your account. `;
            mappedData.forEach(function(mapped) {
            solution += mapped.scheme_name + ' is ' + mapped.NAV + ' '
            });


            Note: I showed map method for giving an insight about what you can do, normally you don't need to simplify, you can directly use for each version.






            share|improve this answer
























              0












              0








              0






              It looks like you try to map that object to another object.



              First, try to read and understand array methods, you can check:



              https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array



              And for map method you can check:



              https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map



              And as a specific answer you can do:



              const mappedData = data.map(function(item) {
              return {
              scheme_name: item.scheme_name,
              NAV: item.NAV
              };
              });


              This will return you an array of a simplified version of yours.



              After that, you can convert it to a string like:



              let solution = `You have ${mappedData.length} schemes linked to your account. `;
              mappedData.forEach(function(mapped) {
              solution += mapped.scheme_name + ' is ' + mapped.NAV + ' '
              });


              Note: I showed map method for giving an insight about what you can do, normally you don't need to simplify, you can directly use for each version.






              share|improve this answer












              It looks like you try to map that object to another object.



              First, try to read and understand array methods, you can check:



              https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array



              And for map method you can check:



              https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map



              And as a specific answer you can do:



              const mappedData = data.map(function(item) {
              return {
              scheme_name: item.scheme_name,
              NAV: item.NAV
              };
              });


              This will return you an array of a simplified version of yours.



              After that, you can convert it to a string like:



              let solution = `You have ${mappedData.length} schemes linked to your account. `;
              mappedData.forEach(function(mapped) {
              solution += mapped.scheme_name + ' is ' + mapped.NAV + ' '
              });


              Note: I showed map method for giving an insight about what you can do, normally you don't need to simplify, you can directly use for each version.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 19 '18 at 16:00









              cenk ebret

              494212




              494212

























                  0














                  Imagine each one of your objects (in this case you have provided two (2)) as an associative array inside of an array. Meaning that rather than reference it by it's index position, you can reference it by it's key.



                  This means to access object 1, you would have to write data[0]. But if you alerted this, this would simply tell you that data[0] is an object. Which is is.



                  To access an actual value in that array, you would then have to provide the key, which you can do by providing a number, or in your case perhaps more easily, it's associated key, which is "scheme_name".



                  See the following :






                  let data = [{
                  "CustomerID": 12345,
                  "NAV": "95.24059718",
                  "cost_of_purchase": 799900,
                  "folio_number": 10007060,
                  "id": 1,
                  "mutual_fund_house": "AXIS MUTUAL FUND",
                  "no_of_units": 15000,
                  "option": "GROWTH",
                  "plan": "REGULAR",
                  "resource_uri": "/api/v1/folio/1/",
                  "scheme_name": "AXIS LONG TERM EQUITY",
                  "value_of_units": "1428608.9580"
                  }, {
                  "CustomerID": 12345,
                  "NAV": "1053.31517400",
                  "cost_of_purchase": 1500000,
                  "folio_number": 5540000567,
                  "id": 2,
                  "mutual_fund_house": "SBI Mutual Fund",
                  "no_of_units": 2750,
                  "option": "DIVIDEND",
                  "plan": "DIRECT",
                  "resource_uri": "/api/v1/folio/2/",
                  "scheme_name": "SBI Magnum Multicap Fund",
                  "value_of_units": "2896616.7270"
                  }]

                  for (let i = 0; i < data.length; i++) {
                  alert(data[i]["scheme_name"]);
                  }





                  So quite simply, for i = 0, with i being less than the number of associative arrays in your array named data, alert the value on that indexed array, by the associated key.






                  share|improve this answer


























                    0














                    Imagine each one of your objects (in this case you have provided two (2)) as an associative array inside of an array. Meaning that rather than reference it by it's index position, you can reference it by it's key.



                    This means to access object 1, you would have to write data[0]. But if you alerted this, this would simply tell you that data[0] is an object. Which is is.



                    To access an actual value in that array, you would then have to provide the key, which you can do by providing a number, or in your case perhaps more easily, it's associated key, which is "scheme_name".



                    See the following :






                    let data = [{
                    "CustomerID": 12345,
                    "NAV": "95.24059718",
                    "cost_of_purchase": 799900,
                    "folio_number": 10007060,
                    "id": 1,
                    "mutual_fund_house": "AXIS MUTUAL FUND",
                    "no_of_units": 15000,
                    "option": "GROWTH",
                    "plan": "REGULAR",
                    "resource_uri": "/api/v1/folio/1/",
                    "scheme_name": "AXIS LONG TERM EQUITY",
                    "value_of_units": "1428608.9580"
                    }, {
                    "CustomerID": 12345,
                    "NAV": "1053.31517400",
                    "cost_of_purchase": 1500000,
                    "folio_number": 5540000567,
                    "id": 2,
                    "mutual_fund_house": "SBI Mutual Fund",
                    "no_of_units": 2750,
                    "option": "DIVIDEND",
                    "plan": "DIRECT",
                    "resource_uri": "/api/v1/folio/2/",
                    "scheme_name": "SBI Magnum Multicap Fund",
                    "value_of_units": "2896616.7270"
                    }]

                    for (let i = 0; i < data.length; i++) {
                    alert(data[i]["scheme_name"]);
                    }





                    So quite simply, for i = 0, with i being less than the number of associative arrays in your array named data, alert the value on that indexed array, by the associated key.






                    share|improve this answer
























                      0












                      0








                      0






                      Imagine each one of your objects (in this case you have provided two (2)) as an associative array inside of an array. Meaning that rather than reference it by it's index position, you can reference it by it's key.



                      This means to access object 1, you would have to write data[0]. But if you alerted this, this would simply tell you that data[0] is an object. Which is is.



                      To access an actual value in that array, you would then have to provide the key, which you can do by providing a number, or in your case perhaps more easily, it's associated key, which is "scheme_name".



                      See the following :






                      let data = [{
                      "CustomerID": 12345,
                      "NAV": "95.24059718",
                      "cost_of_purchase": 799900,
                      "folio_number": 10007060,
                      "id": 1,
                      "mutual_fund_house": "AXIS MUTUAL FUND",
                      "no_of_units": 15000,
                      "option": "GROWTH",
                      "plan": "REGULAR",
                      "resource_uri": "/api/v1/folio/1/",
                      "scheme_name": "AXIS LONG TERM EQUITY",
                      "value_of_units": "1428608.9580"
                      }, {
                      "CustomerID": 12345,
                      "NAV": "1053.31517400",
                      "cost_of_purchase": 1500000,
                      "folio_number": 5540000567,
                      "id": 2,
                      "mutual_fund_house": "SBI Mutual Fund",
                      "no_of_units": 2750,
                      "option": "DIVIDEND",
                      "plan": "DIRECT",
                      "resource_uri": "/api/v1/folio/2/",
                      "scheme_name": "SBI Magnum Multicap Fund",
                      "value_of_units": "2896616.7270"
                      }]

                      for (let i = 0; i < data.length; i++) {
                      alert(data[i]["scheme_name"]);
                      }





                      So quite simply, for i = 0, with i being less than the number of associative arrays in your array named data, alert the value on that indexed array, by the associated key.






                      share|improve this answer












                      Imagine each one of your objects (in this case you have provided two (2)) as an associative array inside of an array. Meaning that rather than reference it by it's index position, you can reference it by it's key.



                      This means to access object 1, you would have to write data[0]. But if you alerted this, this would simply tell you that data[0] is an object. Which is is.



                      To access an actual value in that array, you would then have to provide the key, which you can do by providing a number, or in your case perhaps more easily, it's associated key, which is "scheme_name".



                      See the following :






                      let data = [{
                      "CustomerID": 12345,
                      "NAV": "95.24059718",
                      "cost_of_purchase": 799900,
                      "folio_number": 10007060,
                      "id": 1,
                      "mutual_fund_house": "AXIS MUTUAL FUND",
                      "no_of_units": 15000,
                      "option": "GROWTH",
                      "plan": "REGULAR",
                      "resource_uri": "/api/v1/folio/1/",
                      "scheme_name": "AXIS LONG TERM EQUITY",
                      "value_of_units": "1428608.9580"
                      }, {
                      "CustomerID": 12345,
                      "NAV": "1053.31517400",
                      "cost_of_purchase": 1500000,
                      "folio_number": 5540000567,
                      "id": 2,
                      "mutual_fund_house": "SBI Mutual Fund",
                      "no_of_units": 2750,
                      "option": "DIVIDEND",
                      "plan": "DIRECT",
                      "resource_uri": "/api/v1/folio/2/",
                      "scheme_name": "SBI Magnum Multicap Fund",
                      "value_of_units": "2896616.7270"
                      }]

                      for (let i = 0; i < data.length; i++) {
                      alert(data[i]["scheme_name"]);
                      }





                      So quite simply, for i = 0, with i being less than the number of associative arrays in your array named data, alert the value on that indexed array, by the associated key.






                      let data = [{
                      "CustomerID": 12345,
                      "NAV": "95.24059718",
                      "cost_of_purchase": 799900,
                      "folio_number": 10007060,
                      "id": 1,
                      "mutual_fund_house": "AXIS MUTUAL FUND",
                      "no_of_units": 15000,
                      "option": "GROWTH",
                      "plan": "REGULAR",
                      "resource_uri": "/api/v1/folio/1/",
                      "scheme_name": "AXIS LONG TERM EQUITY",
                      "value_of_units": "1428608.9580"
                      }, {
                      "CustomerID": 12345,
                      "NAV": "1053.31517400",
                      "cost_of_purchase": 1500000,
                      "folio_number": 5540000567,
                      "id": 2,
                      "mutual_fund_house": "SBI Mutual Fund",
                      "no_of_units": 2750,
                      "option": "DIVIDEND",
                      "plan": "DIRECT",
                      "resource_uri": "/api/v1/folio/2/",
                      "scheme_name": "SBI Magnum Multicap Fund",
                      "value_of_units": "2896616.7270"
                      }]

                      for (let i = 0; i < data.length; i++) {
                      alert(data[i]["scheme_name"]);
                      }





                      let data = [{
                      "CustomerID": 12345,
                      "NAV": "95.24059718",
                      "cost_of_purchase": 799900,
                      "folio_number": 10007060,
                      "id": 1,
                      "mutual_fund_house": "AXIS MUTUAL FUND",
                      "no_of_units": 15000,
                      "option": "GROWTH",
                      "plan": "REGULAR",
                      "resource_uri": "/api/v1/folio/1/",
                      "scheme_name": "AXIS LONG TERM EQUITY",
                      "value_of_units": "1428608.9580"
                      }, {
                      "CustomerID": 12345,
                      "NAV": "1053.31517400",
                      "cost_of_purchase": 1500000,
                      "folio_number": 5540000567,
                      "id": 2,
                      "mutual_fund_house": "SBI Mutual Fund",
                      "no_of_units": 2750,
                      "option": "DIVIDEND",
                      "plan": "DIRECT",
                      "resource_uri": "/api/v1/folio/2/",
                      "scheme_name": "SBI Magnum Multicap Fund",
                      "value_of_units": "2896616.7270"
                      }]

                      for (let i = 0; i < data.length; i++) {
                      alert(data[i]["scheme_name"]);
                      }






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 '18 at 15:41









                      cmprogram

                      1,103519




                      1,103519























                          0














                          You've got an array of data so firstly you need to iterate through that array.



                          Pick which properties you want to keep per record, and save them to a results array.



                          Once you have the results you can iterate through them and print out your individual records.






                          let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                          let results =
                          data.forEach(datum => {
                          results.push({
                          scheme_name: datum.scheme_name,
                          nav: datum.NAV,
                          })
                          })

                          console.log(`You've got ${results.length} items in your account.`)
                          results.forEach(result => {
                          console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                          })








                          share|improve this answer




























                            0














                            You've got an array of data so firstly you need to iterate through that array.



                            Pick which properties you want to keep per record, and save them to a results array.



                            Once you have the results you can iterate through them and print out your individual records.






                            let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                            let results =
                            data.forEach(datum => {
                            results.push({
                            scheme_name: datum.scheme_name,
                            nav: datum.NAV,
                            })
                            })

                            console.log(`You've got ${results.length} items in your account.`)
                            results.forEach(result => {
                            console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                            })








                            share|improve this answer


























                              0












                              0








                              0






                              You've got an array of data so firstly you need to iterate through that array.



                              Pick which properties you want to keep per record, and save them to a results array.



                              Once you have the results you can iterate through them and print out your individual records.






                              let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                              let results =
                              data.forEach(datum => {
                              results.push({
                              scheme_name: datum.scheme_name,
                              nav: datum.NAV,
                              })
                              })

                              console.log(`You've got ${results.length} items in your account.`)
                              results.forEach(result => {
                              console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                              })








                              share|improve this answer














                              You've got an array of data so firstly you need to iterate through that array.



                              Pick which properties you want to keep per record, and save them to a results array.



                              Once you have the results you can iterate through them and print out your individual records.






                              let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                              let results =
                              data.forEach(datum => {
                              results.push({
                              scheme_name: datum.scheme_name,
                              nav: datum.NAV,
                              })
                              })

                              console.log(`You've got ${results.length} items in your account.`)
                              results.forEach(result => {
                              console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                              })








                              let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                              let results =
                              data.forEach(datum => {
                              results.push({
                              scheme_name: datum.scheme_name,
                              nav: datum.NAV,
                              })
                              })

                              console.log(`You've got ${results.length} items in your account.`)
                              results.forEach(result => {
                              console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                              })





                              let data = [{"CustomerID":12345,"NAV":"95.24059718","cost_of_purchase":799900,"folio_number":10007060,"id":1,"mutual_fund_house":"AXIS MUTUAL FUND","no_of_units":15000,"option":"GROWTH","plan":"REGULAR","resource_uri":"/api/v1/folio/1/","scheme_name":"AXIS LONG TERM EQUITY","value_of_units":"1428608.9580"},{"CustomerID":12345,"NAV":"1053.31517400","cost_of_purchase":1500000,"folio_number":5540000567,"id":2,"mutual_fund_house":"SBI Mutual Fund","no_of_units":2750,"option":"DIVIDEND","plan":"DIRECT","resource_uri":"/api/v1/folio/2/","scheme_name":"SBI Magnum Multicap Fund","value_of_units":"2896616.7270"}]

                              let results =
                              data.forEach(datum => {
                              results.push({
                              scheme_name: datum.scheme_name,
                              nav: datum.NAV,
                              })
                              })

                              console.log(`You've got ${results.length} items in your account.`)
                              results.forEach(result => {
                              console.log(`${result.scheme_name} - NAV value is: ${result.nav}`)
                              })






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 19 '18 at 15:55

























                              answered Nov 19 '18 at 15:38









                              ksav

                              4,22721329




                              4,22721329























                                  -1














                                  I created sample fiddle for you. You need to iterate over each object in your main object and store all information outside.



                                  data.forEach(function(item) {
                                  console.log(item.scheme_name);
                                  });





                                  share|improve this answer


























                                    -1














                                    I created sample fiddle for you. You need to iterate over each object in your main object and store all information outside.



                                    data.forEach(function(item) {
                                    console.log(item.scheme_name);
                                    });





                                    share|improve this answer
























                                      -1












                                      -1








                                      -1






                                      I created sample fiddle for you. You need to iterate over each object in your main object and store all information outside.



                                      data.forEach(function(item) {
                                      console.log(item.scheme_name);
                                      });





                                      share|improve this answer












                                      I created sample fiddle for you. You need to iterate over each object in your main object and store all information outside.



                                      data.forEach(function(item) {
                                      console.log(item.scheme_name);
                                      });






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 19 '18 at 15:40









                                      dganenco

                                      1977




                                      1977






























                                          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%2f53377885%2fcombining-javascript-object-property-value-and-display%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