"Uncaught TypeError: Array.removeAt() is not a function",

"Uncaught TypeError: Array.removeAt() is not a function",

我有一个 MSDN document for Array.removeAt() 函数。

但是当我尝试它时,出现了这个错误:"Uncaught TypeError: Array.removeAt is not a function",

var a = ['a', 'b', 'c', 'd', 'e'];
Array.removeAt(a, 2);
console.log(a);

为什么它在这里不起作用?那是一份错误的文件吗?

编辑: a.removeAt(a, 2); 也不起作用。

var a = ['a', 'b', 'c', 'd', 'e'];
a.removeAt(a, 2);
console.log(a);

public static void Main()
{
    char[] a = new char[] { 'a', 'b', 'c', 'd', 'e'};
    string str = new string(a);
    int index = str.IndexOf('a');
    str=str.Remove(index,1);
    a = str.ToCharArray();
    Console.WriteLine(a);
}

输出:

bcde

演示:

dotNetFiddle

JavaScript中没有Array.removeAt()函数。

MSDN article is an out of date reference to a JScript (not JavaScript) function.

或者您可以使用 Array.splice() 或其他一些类似的函数。

有关更多信息,请查看此处:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice