Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

javascript - 添加到Array jQuery(Add to Array jQuery)

I know how to initliaize one but how do add I items to an Array?

(我知道如何初始化一个,但如何将我的项目添加到数组?)

I heard it was push() maybe?

(我听说是push()也许?)

I can't find it...

(我找不到......)

  ask by test translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For JavaScript arrays, you use push() .

(对于JavaScript数组,使用push() 。)

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

For jQuery objects, there's add() .

(对于jQuery对象,有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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...