Getting JavaScript object key list

后端 未结 17 1136
野性不改
野性不改 2020-11-22 01:27

I have a JavaScript object like

var obj = {
   key1: \'value1\',
   key2: \'value2\',
   key3: \'value3\',
   key4: \'value4\'
}

How can I

17条回答
  •  你的背包
    2020-11-22 01:59

    Note that in coffeescript this can be accomplished in all browsers and node as

    k for k of obj
    

    and thus

    (1 for _ of obj).length
    

提交回复
热议问题