[英]Array.insert function error as Object function Array() { [native code] } has no method 'insert'
I am working with javascript, HTML, HTTPHandlers and i have used a line in javascript as 我正在使用javascript,HTML,HTTPHandlers,我在javascript中使用了一行
Array.insert( Garray, eval(firstmarker), tmparray);
for this line in Goggle Chrome console have found an error as: 对于Goggle Chrome控制台中的这一行,发现了一个错误:
Uncaught TypeError: Object function Array() { [native code] } has no method 'insert' 未捕获的TypeError:对象函数Array(){[native code]}没有方法'insert'
In the above line the tmparray
contains values and the Garray
is an array declared globally as 在上面的行中, tmparray
包含值,而Garray
是一个全局声明的数组
var Garray = [];
eval(firstmarker)
has the position and initially that is taken as undefined but even if i pass manually 0 it shows the above error in Console. eval(firstmarker)
具有位置,并且最初被视为未定义,但即使我手动传递0,它也会在控制台中显示上述错误。
And the Array.Insert
method found from the link below: 并从以下链接找到Array.Insert
方法:
http://msdn.microsoft.com/en-us/library/bb383995.aspx http://msdn.microsoft.com/en-us/library/bb383995.aspx
I have tried alternatives for this as Arrayname.splice
method and also Arrayname.push
method but it is not working so Can you please help me to solve the above error. 我已经尝试过Arrayname.splice
方法以及Arrayname.push
方法的Arrayname.push
方法,但是它没有用,所以请你帮我解决上面的错误。
Thanking you in advance! 提前感谢你!
The correct method to use is Array#push()
, for example: 正确的方法是使用Array#push()
,例如:
var my_array = [];
my_array.push('apple');
To insert an item into an array at a specific point you can use splice()
( MDN docu ) in the following way: 要在特定点将数组插入数组,可以按以下方式使用splice()
( MDN文档 ):
Garray.splice( firstmarker, 0, yourElement1, yourElement2, ... );
The alternative of push()
( MDN docu ) appends an element to the array: push()
( MDN docu )的替代方法是将一个元素追加到数组中:
Garray.push( yourElement1, yourElement2, ... );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.