how to fetch array keys with jQuery?

前端 未结 6 994
北海茫月
北海茫月 2020-12-03 04:19

Good afternoon. I have an array with some keys, and values in them. I then need to fetch the array keys and not the data in them. I want to do this with jQuery. I know for e

6条回答
  •  悲&欢浪女
    2020-12-03 05:06

    you can use the each function:

    var a = {};
    a['alfa'] = 0;
    a['beta'] = 1;
    $.each(a, function(key, value) {
          alert(key)
    });
    

    it has several nice shortcuts/tricks: check the gory details here

提交回复
热议问题