Check that value is object literal?

后端 未结 12 731
逝去的感伤
逝去的感伤 2020-12-01 10:57

I have a value and want to know if it\'s an iteratable object literal, before I iterate it.

How do I do that?

12条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 11:15

    Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.

    In Lodash, you can easily check it by isPlainObject function, e.g.:

    _.isPlainObject({'a': 12});
    

    Check this page: https://lodash.com/docs#isPlainObject

提交回复
热议问题