Add to Array jQuery

后端 未结 4 1422
一生所求
一生所求 2020-12-07 21:32

I know how to initliaize one but how do add I items to an Array? I heard it was push() maybe? I can\'t find it...

4条回答
  •  不知归路
    2020-12-07 22:21

    For JavaScript arrays, you use push().

    var a = [];
    a.push(12);
    a.push(32);
    

    For jQuery objects, there's add().

    $('div.test').add('p.blue');
    

    Note that while push() modifies the original array in-place, add() returns a new jQuery object, it does not modify the original one.

提交回复
热议问题