[英]Javascript array holds remove function
I am using a an array called "workingLinks", in my javascript function first I define the array as 我正在使用一个名为“workingLinks”的数组,在我的javascript函数中我首先将数组定义为
workingLinks = [];
Then I use console 然后我使用控制台
console.log(workingLinks);
Now the console displays as 现在控制台显示为
[remove: function] ;
here if i use a for
loop it is iterating over the function which i don't want. 在这里如果我使用
for
循环它迭代我不想要的函数。 If I create an array in console then it works fine, shows []
as expected. 如果我在控制台中创建一个数组然后它工作正常,按预期显示
[]
。 Anybody have the idea of how the array holds remove function? 任何人都知道数组如何保持删除功能?
I don't know about the remove function, the guys in the comments were pretty helpful. 我不知道删除功能,评论中的人非常有帮助。
However, you can simply iterate an array with the forEach
function like so: 但是,您可以使用
forEach
函数简单地迭代数组,如下所示:
arr.forEach(functionToRunForEachElement);
It also accepts anonymous functions: 它还接受匿名函数:
arr.forEach(function(element, index, originalArray) {
//Do stuff here
});
There are also .map
and .reduce
to perform common actions like mapping all the values of the array to something else, or reduce the array of values into a single value. 还有
.map
和.reduce
来执行常见操作,例如将数组的所有值映射到其他值,或者将值数组减少为单个值。
Something has modified the Array prototype. 有些东西修改了Array原型。 I tried this in Chrome:
我在Chrome中试过这个:
Array.prototype.remove = function () {};
> function () {}
console.log([]);
> [remove: function]
What other libraries are you using? 您使用的是哪些其他库?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.