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

前端 未结 5 713
余生分开走
余生分开走 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:45

    There is has method in lodash library for this. It can even check for nested fields.

    _.has(object, 'a');     
    _.has(object, 'a.b');
    

提交回复
热议问题