How to iterate over an array of objects?

  • 0
    Working with api I get this construction.
    [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, { …}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {...}, {…}, {…} , {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, { …}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {...}, {…}, {…} , {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, { …}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {...}, {…}, {…} , {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, { …}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {...}, {…}, {…} ,…]

    if you open up
    [0 ... 99]
    [100 ... 199]
    [200 ... 299]
    [300 ... 399]
    [400 ... 499]
    [500 ... 599]
    [600 ... 699]
    [700 ... 799]
    [800 ... 899]
    [900 ... 999]

    in each array of objects, each object has a name key, how can I iterate over the whole thing and get a list of all names?
    JavaScript Collin Jackson, Jul 27, 2019

  • 2 Answers
  • 0
    const names = data.map (obj = & gt; obj.name);
    Adeline Nichols

  • 0
    In arr put your array, and then just loop over it:

    for (var n = 0; n < arr.length; n++) {
    console.log(arr[n]['name']);
    }


    Details: https://learn.javascript.com/while-for#tsikl-for
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!