Get array of object's keys

前端 未结 7 1203
死守一世寂寞
死守一世寂寞 2020-11-22 05:41

I would like to get the keys of a JavaScript object as an array, either in jQuery or pure JavaScript.

Is there a less verbose way than this?

var foo          


        
相关标签:
7条回答
  • 2020-11-22 06:11

    You can use jQuery's $.map.

    var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' },
    keys = $.map(foo, function(v, i){
      return i;
    });
    
    0 讨论(0)
提交回复
热议问题