How to loop array one column data












0














I have an array like this.



[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]


Now I need to get the Recommendedby column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid.



Please tell me how to achieve this.










share|improve this question
























  • your js object is not valid
    – Suraj Rao
    Nov 12 '18 at 14:49










  • can you provide expected array
    – Naga Sai A
    Nov 12 '18 at 14:51










  • This might be what you're after: stackoverflow.com/questions/18804592/…
    – DonCarlosII
    Nov 12 '18 at 14:53
















0














I have an array like this.



[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]


Now I need to get the Recommendedby column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid.



Please tell me how to achieve this.










share|improve this question
























  • your js object is not valid
    – Suraj Rao
    Nov 12 '18 at 14:49










  • can you provide expected array
    – Naga Sai A
    Nov 12 '18 at 14:51










  • This might be what you're after: stackoverflow.com/questions/18804592/…
    – DonCarlosII
    Nov 12 '18 at 14:53














0












0








0







I have an array like this.



[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]


Now I need to get the Recommendedby column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid.



Please tell me how to achieve this.










share|improve this question















I have an array like this.



[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]


Now I need to get the Recommendedby column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid.



Please tell me how to achieve this.







javascript angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 14:52









Jacob van Lingen

4,63422951




4,63422951










asked Nov 12 '18 at 14:03









Prasanna

134




134












  • your js object is not valid
    – Suraj Rao
    Nov 12 '18 at 14:49










  • can you provide expected array
    – Naga Sai A
    Nov 12 '18 at 14:51










  • This might be what you're after: stackoverflow.com/questions/18804592/…
    – DonCarlosII
    Nov 12 '18 at 14:53


















  • your js object is not valid
    – Suraj Rao
    Nov 12 '18 at 14:49










  • can you provide expected array
    – Naga Sai A
    Nov 12 '18 at 14:51










  • This might be what you're after: stackoverflow.com/questions/18804592/…
    – DonCarlosII
    Nov 12 '18 at 14:53
















your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49




your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49












can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51




can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51












This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53




This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53












2 Answers
2






active

oldest

votes


















0














To achieve expected use below option of looping through array with forEach




  1. Use forEach to loop through array

  2. Use split with comma to create another array for Recommendedby

  3. Use anoher forEach to loop through Recommendedby array





let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))





codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010






share|improve this answer





















  • Thank you..you saved my time.
    – Prasanna
    Nov 13 '18 at 8:45










  • np.. Glad it worked :)
    – Naga Sai A
    Nov 13 '18 at 14:38



















0














Try like this :



let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]




array.map(item => item.Recommendedby.split(',').map(id => {

// this.http.getUser(id).subscribe(...)

}))





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%2f53263794%2fhow-to-loop-array-one-column-data%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To achieve expected use below option of looping through array with forEach




    1. Use forEach to loop through array

    2. Use split with comma to create another array for Recommendedby

    3. Use anoher forEach to loop through Recommendedby array





    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))





    codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010






    share|improve this answer





















    • Thank you..you saved my time.
      – Prasanna
      Nov 13 '18 at 8:45










    • np.. Glad it worked :)
      – Naga Sai A
      Nov 13 '18 at 14:38
















    0














    To achieve expected use below option of looping through array with forEach




    1. Use forEach to loop through array

    2. Use split with comma to create another array for Recommendedby

    3. Use anoher forEach to loop through Recommendedby array





    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))





    codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010






    share|improve this answer





















    • Thank you..you saved my time.
      – Prasanna
      Nov 13 '18 at 8:45










    • np.. Glad it worked :)
      – Naga Sai A
      Nov 13 '18 at 14:38














    0












    0








    0






    To achieve expected use below option of looping through array with forEach




    1. Use forEach to loop through array

    2. Use split with comma to create another array for Recommendedby

    3. Use anoher forEach to loop through Recommendedby array





    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))





    codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010






    share|improve this answer












    To achieve expected use below option of looping through array with forEach




    1. Use forEach to loop through array

    2. Use split with comma to create another array for Recommendedby

    3. Use anoher forEach to loop through Recommendedby array





    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))





    codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010






    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))





    let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]

    arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
    console.log("Recommended by id-", val); // make service call here to pass each id
    }))






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 12 '18 at 14:56









    Naga Sai A

    5,5121825




    5,5121825












    • Thank you..you saved my time.
      – Prasanna
      Nov 13 '18 at 8:45










    • np.. Glad it worked :)
      – Naga Sai A
      Nov 13 '18 at 14:38


















    • Thank you..you saved my time.
      – Prasanna
      Nov 13 '18 at 8:45










    • np.. Glad it worked :)
      – Naga Sai A
      Nov 13 '18 at 14:38
















    Thank you..you saved my time.
    – Prasanna
    Nov 13 '18 at 8:45




    Thank you..you saved my time.
    – Prasanna
    Nov 13 '18 at 8:45












    np.. Glad it worked :)
    – Naga Sai A
    Nov 13 '18 at 14:38




    np.. Glad it worked :)
    – Naga Sai A
    Nov 13 '18 at 14:38













    0














    Try like this :



    let array = [
    {"Test":1,"Recommendedby":"3,4,5,6"},
    {"ABC":"2","Recommendedby":"1,2,3"},
    {"Cvb":"3","Recommendedby":""}
    ]




    array.map(item => item.Recommendedby.split(',').map(id => {

    // this.http.getUser(id).subscribe(...)

    }))





    share|improve this answer




























      0














      Try like this :



      let array = [
      {"Test":1,"Recommendedby":"3,4,5,6"},
      {"ABC":"2","Recommendedby":"1,2,3"},
      {"Cvb":"3","Recommendedby":""}
      ]




      array.map(item => item.Recommendedby.split(',').map(id => {

      // this.http.getUser(id).subscribe(...)

      }))





      share|improve this answer


























        0












        0








        0






        Try like this :



        let array = [
        {"Test":1,"Recommendedby":"3,4,5,6"},
        {"ABC":"2","Recommendedby":"1,2,3"},
        {"Cvb":"3","Recommendedby":""}
        ]




        array.map(item => item.Recommendedby.split(',').map(id => {

        // this.http.getUser(id).subscribe(...)

        }))





        share|improve this answer














        Try like this :



        let array = [
        {"Test":1,"Recommendedby":"3,4,5,6"},
        {"ABC":"2","Recommendedby":"1,2,3"},
        {"Cvb":"3","Recommendedby":""}
        ]




        array.map(item => item.Recommendedby.split(',').map(id => {

        // this.http.getUser(id).subscribe(...)

        }))






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 '18 at 15:10









        Suraj Rao

        22.6k75469




        22.6k75469










        answered Nov 12 '18 at 14:59









        Abderrahim Soubai Elidrissi

        1,41011020




        1,41011020






























            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%2f53263794%2fhow-to-loop-array-one-column-data%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

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma