admin管理员组

文章数量:1353114

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

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

Share Improve this question edited May 24, 2018 at 4:44 Ramesh Rajendran asked May 24, 2018 at 4:42 Ramesh RajendranRamesh Rajendran 38.7k49 gold badges159 silver badges239 bronze badges 4
  • a.removeAt(a, 2);? – DirtyBit Commented May 24, 2018 at 4:43
  • @user5173426 That's also not working and getting the same error. – Ramesh Rajendran Commented May 24, 2018 at 4:43
  • Yeah, I know how can i do delete. but my question is that document is correct or not? – Ramesh Rajendran Commented May 24, 2018 at 4:50
  • 1 the documentation is an out of date reference to a jscript (not javascript) function. – Claies Commented May 24, 2018 at 4:51
Add a ment  | 

2 Answers 2

Reset to default 7

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/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

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

本文标签: javascriptquotUncaught TypeError ArrayremoveAt() is not a functionquot Stack Overflow