How to access the first property of a Javascript object?

前端 未结 19 2446
爱一瞬间的悲伤
爱一瞬间的悲伤 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:38

    No. An object literal, as defined by MDC is:

    a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}).

    Therefore an object literal is not an array, and you can only access the properties using their explicit name or a for loop using the in keyword.

提交回复
热议问题