Array of objects , group by parent's object












0














I've got an array of objects. I want to be able to group objects in parent's object , parent object is determined by broker: true. Is there a way to convert this:



const data = [
{ id: 1, broker: true },
{ id: 2, broker: false },
{ id: 3, broker: false },
{ id: 4, broker: true },
{ id: 5, broker: false },
{ id: 6, broker: true },
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
];


Into something like this:



const data = [
{ id: 1, broker: true, chunks: [
{ id: 2, broker: false },
{ id: 3, broker: false },
]},
{ id: 4, broker: true, chunks: [
{ id: 5, broker: false },
]},
{ id: 6, broker: true, chunks: [
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
]},
];









share|improve this question




















  • 1




    where is you specific problem?
    – Nina Scholz
    Nov 23 '18 at 18:55










  • @NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
    – Dorin Musteața
    Nov 23 '18 at 18:58












  • have you tried anything?
    – Nina Scholz
    Nov 23 '18 at 18:59










  • @NinaScholz Of course , that's why asked , thanks for the right answer anyway.
    – Dorin Musteața
    Nov 23 '18 at 19:07










  • "Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
    – Andreas
    Nov 23 '18 at 19:09
















0














I've got an array of objects. I want to be able to group objects in parent's object , parent object is determined by broker: true. Is there a way to convert this:



const data = [
{ id: 1, broker: true },
{ id: 2, broker: false },
{ id: 3, broker: false },
{ id: 4, broker: true },
{ id: 5, broker: false },
{ id: 6, broker: true },
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
];


Into something like this:



const data = [
{ id: 1, broker: true, chunks: [
{ id: 2, broker: false },
{ id: 3, broker: false },
]},
{ id: 4, broker: true, chunks: [
{ id: 5, broker: false },
]},
{ id: 6, broker: true, chunks: [
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
]},
];









share|improve this question




















  • 1




    where is you specific problem?
    – Nina Scholz
    Nov 23 '18 at 18:55










  • @NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
    – Dorin Musteața
    Nov 23 '18 at 18:58












  • have you tried anything?
    – Nina Scholz
    Nov 23 '18 at 18:59










  • @NinaScholz Of course , that's why asked , thanks for the right answer anyway.
    – Dorin Musteața
    Nov 23 '18 at 19:07










  • "Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
    – Andreas
    Nov 23 '18 at 19:09














0












0








0







I've got an array of objects. I want to be able to group objects in parent's object , parent object is determined by broker: true. Is there a way to convert this:



const data = [
{ id: 1, broker: true },
{ id: 2, broker: false },
{ id: 3, broker: false },
{ id: 4, broker: true },
{ id: 5, broker: false },
{ id: 6, broker: true },
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
];


Into something like this:



const data = [
{ id: 1, broker: true, chunks: [
{ id: 2, broker: false },
{ id: 3, broker: false },
]},
{ id: 4, broker: true, chunks: [
{ id: 5, broker: false },
]},
{ id: 6, broker: true, chunks: [
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
]},
];









share|improve this question















I've got an array of objects. I want to be able to group objects in parent's object , parent object is determined by broker: true. Is there a way to convert this:



const data = [
{ id: 1, broker: true },
{ id: 2, broker: false },
{ id: 3, broker: false },
{ id: 4, broker: true },
{ id: 5, broker: false },
{ id: 6, broker: true },
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
];


Into something like this:



const data = [
{ id: 1, broker: true, chunks: [
{ id: 2, broker: false },
{ id: 3, broker: false },
]},
{ id: 4, broker: true, chunks: [
{ id: 5, broker: false },
]},
{ id: 6, broker: true, chunks: [
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
]},
];






javascript arrays sorting ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 18:57









dince12

390215




390215










asked Nov 23 '18 at 18:51









Dorin MusteațaDorin Musteața

35110




35110








  • 1




    where is you specific problem?
    – Nina Scholz
    Nov 23 '18 at 18:55










  • @NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
    – Dorin Musteața
    Nov 23 '18 at 18:58












  • have you tried anything?
    – Nina Scholz
    Nov 23 '18 at 18:59










  • @NinaScholz Of course , that's why asked , thanks for the right answer anyway.
    – Dorin Musteața
    Nov 23 '18 at 19:07










  • "Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
    – Andreas
    Nov 23 '18 at 19:09














  • 1




    where is you specific problem?
    – Nina Scholz
    Nov 23 '18 at 18:55










  • @NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
    – Dorin Musteața
    Nov 23 '18 at 18:58












  • have you tried anything?
    – Nina Scholz
    Nov 23 '18 at 18:59










  • @NinaScholz Of course , that's why asked , thanks for the right answer anyway.
    – Dorin Musteața
    Nov 23 '18 at 19:07










  • "Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
    – Andreas
    Nov 23 '18 at 19:09








1




1




where is you specific problem?
– Nina Scholz
Nov 23 '18 at 18:55




where is you specific problem?
– Nina Scholz
Nov 23 '18 at 18:55












@NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
– Dorin Musteața
Nov 23 '18 at 18:58






@NinaScholz what do you mean? I want to be able to group objects in parent's object. I cant achieve that kind of grouping.
– Dorin Musteața
Nov 23 '18 at 18:58














have you tried anything?
– Nina Scholz
Nov 23 '18 at 18:59




have you tried anything?
– Nina Scholz
Nov 23 '18 at 18:59












@NinaScholz Of course , that's why asked , thanks for the right answer anyway.
– Dorin Musteața
Nov 23 '18 at 19:07




@NinaScholz Of course , that's why asked , thanks for the right answer anyway.
– Dorin Musteața
Nov 23 '18 at 19:07












"Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
– Andreas
Nov 23 '18 at 19:09




"Of course , that's why asked" - Then why didn't you post your code? Just copy&pasting the answer from somebody won't help you understand what you've done wrong.
– Andreas
Nov 23 '18 at 19:09












4 Answers
4






active

oldest

votes


















1














You could check the propery for broker and push either a new object to the result set, or push the object to the previous object's chunks array.






const
data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
grouped = data.reduce((r, o) => {
if (o.broker) {
r.push(Object.assign({}, o, { chunks: }));
} else {
r[r.length - 1].chunks.push(o);
}
return r;
}, );

console.log(grouped);

.as-console-wrapper { max-height: 100% !important; top: 0; }








share|improve this answer





















  • That will work out. Thanks.
    – Dorin Musteața
    Nov 23 '18 at 19:07



















0














Use reduce to add to an accumulator every time it runs into a true value, and if it runs into a false value, add to the previous object via the property chunks



data.reduce((a, cv) => {
let len = a.length - 1;
return (cv["broker"]) ? (a.push(cv), a) : (a[len]
["chunks"] || (a[len]["chunks"] = ), a[len]
["chunks"].push(cv), a);
}, );





const data = [
{ id: 1, broker: true },
{ id: 2, broker: false },
{ id: 3, broker: false },
{ id: 4, broker: true },
{ id: 5, broker: false },
{ id: 6, broker: true },
{ id: 7, broker: false },
{ id: 8, broker: false },
{ id: 9, broker: false },
];

let result = data.reduce((a, cv) => {
let len = a.length - 1;
return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
}, );

console.log(result);








share|improve this answer





























    -1














    You have to go through the array, create a new one and evaluate the condition you need, if it is met, put it in the new array






    Object.keys(data).forEach((value, index) => {

    // code

    })








    share|improve this answer





















    • Object.keys() for an array? O.o
      – Andreas
      Nov 23 '18 at 18:59










    • Object.keys(data).forEach(key => { console.log(data[key].property) })
      – Darwin Rodríguez
      Nov 23 '18 at 19:16












    • Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
      – Andreas
      Nov 23 '18 at 19:19



















    -1














    You are going through the keys of each object






    Object.keys(data).forEach(key => {
    console.log(data[index].property)
    })





    found






    share|improve this answer





















    • Why the same "answer" twice?
      – Andreas
      Nov 23 '18 at 19:31










    • Remember that it is an array of objects therefore you can use foreach
      – Darwin Rodríguez
      Nov 23 '18 at 19:32










    • See my comment on your other answer...
      – Andreas
      Nov 23 '18 at 19:32











    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%2f53451691%2farray-of-objects-group-by-parents-object%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









    1














    You could check the propery for broker and push either a new object to the result set, or push the object to the previous object's chunks array.






    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }








    share|improve this answer





















    • That will work out. Thanks.
      – Dorin Musteața
      Nov 23 '18 at 19:07
















    1














    You could check the propery for broker and push either a new object to the result set, or push the object to the previous object's chunks array.






    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }








    share|improve this answer





















    • That will work out. Thanks.
      – Dorin Musteața
      Nov 23 '18 at 19:07














    1












    1








    1






    You could check the propery for broker and push either a new object to the result set, or push the object to the previous object's chunks array.






    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }








    share|improve this answer












    You could check the propery for broker and push either a new object to the result set, or push the object to the previous object's chunks array.






    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }








    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }





    const
    data = [{ id: 1, broker: true }, { id: 2, broker: false }, { id: 3, broker: false }, { id: 4, broker: true }, { id: 5, broker: false }, { id: 6, broker: true }, { id: 7, broker: false }, { id: 8, broker: false }, { id: 9, broker: false }],
    grouped = data.reduce((r, o) => {
    if (o.broker) {
    r.push(Object.assign({}, o, { chunks: }));
    } else {
    r[r.length - 1].chunks.push(o);
    }
    return r;
    }, );

    console.log(grouped);

    .as-console-wrapper { max-height: 100% !important; top: 0; }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 18:59









    Nina ScholzNina Scholz

    177k1391156




    177k1391156












    • That will work out. Thanks.
      – Dorin Musteața
      Nov 23 '18 at 19:07


















    • That will work out. Thanks.
      – Dorin Musteața
      Nov 23 '18 at 19:07
















    That will work out. Thanks.
    – Dorin Musteața
    Nov 23 '18 at 19:07




    That will work out. Thanks.
    – Dorin Musteața
    Nov 23 '18 at 19:07













    0














    Use reduce to add to an accumulator every time it runs into a true value, and if it runs into a false value, add to the previous object via the property chunks



    data.reduce((a, cv) => {
    let len = a.length - 1;
    return (cv["broker"]) ? (a.push(cv), a) : (a[len]
    ["chunks"] || (a[len]["chunks"] = ), a[len]
    ["chunks"].push(cv), a);
    }, );





    const data = [
    { id: 1, broker: true },
    { id: 2, broker: false },
    { id: 3, broker: false },
    { id: 4, broker: true },
    { id: 5, broker: false },
    { id: 6, broker: true },
    { id: 7, broker: false },
    { id: 8, broker: false },
    { id: 9, broker: false },
    ];

    let result = data.reduce((a, cv) => {
    let len = a.length - 1;
    return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
    }, );

    console.log(result);








    share|improve this answer


























      0














      Use reduce to add to an accumulator every time it runs into a true value, and if it runs into a false value, add to the previous object via the property chunks



      data.reduce((a, cv) => {
      let len = a.length - 1;
      return (cv["broker"]) ? (a.push(cv), a) : (a[len]
      ["chunks"] || (a[len]["chunks"] = ), a[len]
      ["chunks"].push(cv), a);
      }, );





      const data = [
      { id: 1, broker: true },
      { id: 2, broker: false },
      { id: 3, broker: false },
      { id: 4, broker: true },
      { id: 5, broker: false },
      { id: 6, broker: true },
      { id: 7, broker: false },
      { id: 8, broker: false },
      { id: 9, broker: false },
      ];

      let result = data.reduce((a, cv) => {
      let len = a.length - 1;
      return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
      }, );

      console.log(result);








      share|improve this answer
























        0












        0








        0






        Use reduce to add to an accumulator every time it runs into a true value, and if it runs into a false value, add to the previous object via the property chunks



        data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]
        ["chunks"] || (a[len]["chunks"] = ), a[len]
        ["chunks"].push(cv), a);
        }, );





        const data = [
        { id: 1, broker: true },
        { id: 2, broker: false },
        { id: 3, broker: false },
        { id: 4, broker: true },
        { id: 5, broker: false },
        { id: 6, broker: true },
        { id: 7, broker: false },
        { id: 8, broker: false },
        { id: 9, broker: false },
        ];

        let result = data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
        }, );

        console.log(result);








        share|improve this answer












        Use reduce to add to an accumulator every time it runs into a true value, and if it runs into a false value, add to the previous object via the property chunks



        data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]
        ["chunks"] || (a[len]["chunks"] = ), a[len]
        ["chunks"].push(cv), a);
        }, );





        const data = [
        { id: 1, broker: true },
        { id: 2, broker: false },
        { id: 3, broker: false },
        { id: 4, broker: true },
        { id: 5, broker: false },
        { id: 6, broker: true },
        { id: 7, broker: false },
        { id: 8, broker: false },
        { id: 9, broker: false },
        ];

        let result = data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
        }, );

        console.log(result);








        const data = [
        { id: 1, broker: true },
        { id: 2, broker: false },
        { id: 3, broker: false },
        { id: 4, broker: true },
        { id: 5, broker: false },
        { id: 6, broker: true },
        { id: 7, broker: false },
        { id: 8, broker: false },
        { id: 9, broker: false },
        ];

        let result = data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
        }, );

        console.log(result);





        const data = [
        { id: 1, broker: true },
        { id: 2, broker: false },
        { id: 3, broker: false },
        { id: 4, broker: true },
        { id: 5, broker: false },
        { id: 6, broker: true },
        { id: 7, broker: false },
        { id: 8, broker: false },
        { id: 9, broker: false },
        ];

        let result = data.reduce((a, cv) => {
        let len = a.length - 1;
        return (cv["broker"]) ? (a.push(cv), a) : (a[len]["chunks"] || (a[len]["chunks"] = ), a[len]["chunks"].push(cv), a);
        }, );

        console.log(result);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 19:06









        zfrischzfrisch

        4,42811024




        4,42811024























            -1














            You have to go through the array, create a new one and evaluate the condition you need, if it is met, put it in the new array






            Object.keys(data).forEach((value, index) => {

            // code

            })








            share|improve this answer





















            • Object.keys() for an array? O.o
              – Andreas
              Nov 23 '18 at 18:59










            • Object.keys(data).forEach(key => { console.log(data[key].property) })
              – Darwin Rodríguez
              Nov 23 '18 at 19:16












            • Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
              – Andreas
              Nov 23 '18 at 19:19
















            -1














            You have to go through the array, create a new one and evaluate the condition you need, if it is met, put it in the new array






            Object.keys(data).forEach((value, index) => {

            // code

            })








            share|improve this answer





















            • Object.keys() for an array? O.o
              – Andreas
              Nov 23 '18 at 18:59










            • Object.keys(data).forEach(key => { console.log(data[key].property) })
              – Darwin Rodríguez
              Nov 23 '18 at 19:16












            • Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
              – Andreas
              Nov 23 '18 at 19:19














            -1












            -1








            -1






            You have to go through the array, create a new one and evaluate the condition you need, if it is met, put it in the new array






            Object.keys(data).forEach((value, index) => {

            // code

            })








            share|improve this answer












            You have to go through the array, create a new one and evaluate the condition you need, if it is met, put it in the new array






            Object.keys(data).forEach((value, index) => {

            // code

            })








            Object.keys(data).forEach((value, index) => {

            // code

            })





            Object.keys(data).forEach((value, index) => {

            // code

            })






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 18:59









            Darwin RodríguezDarwin Rodríguez

            1




            1












            • Object.keys() for an array? O.o
              – Andreas
              Nov 23 '18 at 18:59










            • Object.keys(data).forEach(key => { console.log(data[key].property) })
              – Darwin Rodríguez
              Nov 23 '18 at 19:16












            • Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
              – Andreas
              Nov 23 '18 at 19:19


















            • Object.keys() for an array? O.o
              – Andreas
              Nov 23 '18 at 18:59










            • Object.keys(data).forEach(key => { console.log(data[key].property) })
              – Darwin Rodríguez
              Nov 23 '18 at 19:16












            • Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
              – Andreas
              Nov 23 '18 at 19:19
















            Object.keys() for an array? O.o
            – Andreas
            Nov 23 '18 at 18:59




            Object.keys() for an array? O.o
            – Andreas
            Nov 23 '18 at 18:59












            Object.keys(data).forEach(key => { console.log(data[key].property) })
            – Darwin Rodríguez
            Nov 23 '18 at 19:16






            Object.keys(data).forEach(key => { console.log(data[key].property) })
            – Darwin Rodríguez
            Nov 23 '18 at 19:16














            Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
            – Andreas
            Nov 23 '18 at 19:19




            Like the Object in Object.keys already suggests, is this method for objects and not for arrays.
            – Andreas
            Nov 23 '18 at 19:19











            -1














            You are going through the keys of each object






            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })





            found






            share|improve this answer





















            • Why the same "answer" twice?
              – Andreas
              Nov 23 '18 at 19:31










            • Remember that it is an array of objects therefore you can use foreach
              – Darwin Rodríguez
              Nov 23 '18 at 19:32










            • See my comment on your other answer...
              – Andreas
              Nov 23 '18 at 19:32
















            -1














            You are going through the keys of each object






            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })





            found






            share|improve this answer





















            • Why the same "answer" twice?
              – Andreas
              Nov 23 '18 at 19:31










            • Remember that it is an array of objects therefore you can use foreach
              – Darwin Rodríguez
              Nov 23 '18 at 19:32










            • See my comment on your other answer...
              – Andreas
              Nov 23 '18 at 19:32














            -1












            -1








            -1






            You are going through the keys of each object






            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })





            found






            share|improve this answer












            You are going through the keys of each object






            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })





            found






            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })





            Object.keys(data).forEach(key => {
            console.log(data[index].property)
            })






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 19:13









            Darwin RodríguezDarwin Rodríguez

            1




            1












            • Why the same "answer" twice?
              – Andreas
              Nov 23 '18 at 19:31










            • Remember that it is an array of objects therefore you can use foreach
              – Darwin Rodríguez
              Nov 23 '18 at 19:32










            • See my comment on your other answer...
              – Andreas
              Nov 23 '18 at 19:32


















            • Why the same "answer" twice?
              – Andreas
              Nov 23 '18 at 19:31










            • Remember that it is an array of objects therefore you can use foreach
              – Darwin Rodríguez
              Nov 23 '18 at 19:32










            • See my comment on your other answer...
              – Andreas
              Nov 23 '18 at 19:32
















            Why the same "answer" twice?
            – Andreas
            Nov 23 '18 at 19:31




            Why the same "answer" twice?
            – Andreas
            Nov 23 '18 at 19:31












            Remember that it is an array of objects therefore you can use foreach
            – Darwin Rodríguez
            Nov 23 '18 at 19:32




            Remember that it is an array of objects therefore you can use foreach
            – Darwin Rodríguez
            Nov 23 '18 at 19:32












            See my comment on your other answer...
            – Andreas
            Nov 23 '18 at 19:32




            See my comment on your other answer...
            – Andreas
            Nov 23 '18 at 19:32


















            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%2f53451691%2farray-of-objects-group-by-parents-object%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

            Lallio

            Unable to find Lightning Node

            Futebolista