Shebin Mathew
Shebin Mathew

Reputation: 318

Javascript array holds remove function

I am using a an array called "workingLinks", in my javascript function first I define the array as

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. 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?

Upvotes: 1

Views: 62

Answers (2)

Madara's Ghost
Madara's Ghost

Reputation: 175017

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:

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.

Upvotes: 2

Nicholas Cloud
Nicholas Cloud

Reputation: 1574

Something has modified the Array prototype. I tried this in Chrome:

Array.prototype.remove = function () {};
> function () {}
console.log([]);
> [remove: function]

What other libraries are you using?

Upvotes: 1

Related Questions