In Javascript. how can I tell if a field exists inside an object?

前端 未结 5 841
余生分开走
余生分开走 2021-01-31 07:12

And of course I want to do this code-wise. It\'s not that there isn\'t alternative to this problem I\'m facing, just curious.

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 07:29

    In addition to the above, you can use following way:

    if(obj.myProperty !== undefined) {
    }
    

提交回复
热议问题