Dynamic property names for loop of object Javascript

前端 未结 3 1354
北荒
北荒 2020-12-21 09:57

In Javascript is there a clever way to loop through the names of properties in objects in an array?

I have objects with several properties including guest1 to guest1

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-21 10:33

    I think you'll find useful the "in" operator:

    if (("guest" + i) in results[i]) { /*code*/ } 
    

    Cheers

提交回复
热议问题