首页 > 编程语言 > 详细

[Javascript] JavaScript Array Methods in Depth - push

时间:2016-04-13 07:02:20      阅读:131      评论:0      收藏:0      [点我收藏+]

Array push is used to add elements to the end of an Array. In this lesson we‘ll see how the push method accepts multiple arguments, can be used to merge two arrays,.

 

Push can accept multi args:

const pets = ["dog", "hamster"];
pets.push("cat");
console.log(pets); //["dog", "hamster", "cat"]

pets.push("brid", "horse");
console.log(pets); //["dog", "hamster", "cat", "brid", "horse"]

 

Push can merge two arrays:

const pets = ["dog", "hamster"];
const pets2 = ["Hamster", "cat"];
pets.push.apply(pets, pets2);
console.log(pets); //["dog", "hamster", "Hamster", "cat"]

 

[Javascript] JavaScript Array Methods in Depth - push

原文:http://www.cnblogs.com/Answer1215/p/5385346.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!