Loop through properties in JavaScript object with Lodash

后端 未结 7 1954
闹比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:44

    Use _.forOwn().

    _.forOwn(obj, function(value, key) { } );
    

    https://lodash.com/docs#forOwn

    Note that forOwn checks hasOwnProperty, as you usually need to do when looping over an object's properties. forIn does not do this check.

提交回复
热议问题