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

房东的猫 提交于 2019-12-11 05:59:15

问题


I got a MSDN document for Array.removeAt() function.

But when i trying it, I am getting this error : "Uncaught TypeError: Array.removeAt is not a function",

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

Why it's not working here? And is that is a wrong document?

Edit: a.removeAt(a, 2); also not working.

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

回答1:


There is no Array.removeAt() function in JavaScript.

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

Alternatively you can use Array.splice() or some other similar functions.

For more information check here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice




回答2:


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);
}

OUTPUT:

bcde

DEMO:

dotNetFiddle



来源:https://stackoverflow.com/questions/50501112/uncaught-typeerror-array-removeat-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!