Loop through properties in JavaScript object with Lodash

后端 未结 7 1948
闹比i
闹比i 2021-02-01 00:01

Is it possible to loop through the properties in a JavaScript object? For instance, I have a JavaScript object defined as this:

myObject.options = {
  property1:         


        
7条回答
  •  情话喂你
    2021-02-01 00:43

    It would be helpful to understand why you need to do this with lodash. If you just want to check if a key exists in an object, you don't need lodash.

    myObject.options.hasOwnProperty('property');
    

    If your looking to see if a value exists, you can use _.invert

    _.invert(myObject.options)[value]
    

提交回复
热议问题