本文实例讲述了javascript数组前面插入元素的方法。分享给大家供大家参考。具体如下:
js数组带有一个unshift方法可以再数组前面添加若干个元素,下面是详细的代码演示
复制代码 代码如下:
click the button to add elements to the array.
try it
note: the unshift() method does not work properly in internet explorer 8 and earlier, the values will be inserted, but the return value will be undefined.
执行后数组会变成下面的样子
lemon,pineapple,banana,orange,apple,mango
unshift在ie8及之前的版本工作有些问题,数组会插入元素,但是返回值是undefined
希望本文所述对大家的javascript程序设计有所帮助。
