How to access the first property of a Javascript object?

前端 未结 19 2872
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 09:00

Is there an elegant way to access the first property of an object...

  1. where you don\'t know the name of your properties
  2. without using a loop like
19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 09:33

    Solution with lodash library:

    _.find(example) // => {name: "foo1"}
    

    but there is no guarantee of the object properties internal storage order because it depends on javascript VM implementation.

提交回复
热议问题