As I read from the internet I found that I can extend the functionally of inbuild class using prototype
. I added some custom functions in Array class like getting the last element from split() function like let file = split("/").last()
Here code how I added the custom function to Array class
Array.prototype.last = function () {
return this[this.length - 1];
}
When any array iterating it add custom function names also with the iteration
let fields = ["test","xyz"];
for(let index in fields) {
}
Above loop iterate for the "last method" also.
As I added 3 functions to Array class named "last", "removeLastElement", "toJson" to extend by using prototype
.
Above array iterate 5 times with my custom Array method.
How can I avoid my custom function from an iterating array?
here I debug the array field I found that custom methods for Array class are shown as dark-colored where other inbuilt functions like light colored