添加到Array jQuery [英] Add to Array jQuery

查看:113
本文介绍了添加到Array jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何初始化一个但是如何将I项添加到数组?我听说它是​​ push()也许?我找不到它...

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...

推荐答案

对于JavaScript数组,使用 push()

For JavaScript arrays, you use push().

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

对于jQuery对象,有 add()

For jQuery objects, there's add().

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

请注意,当 push()修改原始数组就地, add()返回一个新的jQuery对象,它不会修改原始对象。

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

这篇关于添加到Array jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆