I am not that experienced in JS so maybe this is a very naive question. I tried to call
"".forEach((e, i) => {
console.log(e)
})
And I get an error saying that forEach
is not a function for a string. Yet when I call:
Object.getOwnProperyNames("")
I can clearly see that forEach()
is in the prototype of the string and of type function
.
Why can I not call it on a string?
I can clearly see that forEach() is in the prototype of the string and of type function.
where you can see this,forEach
is not available on String.getOwnPropertyNames()
has a.forEach
method because it's an array.forEach
function?Object.getOwnProperyNames("")
not the correct way to do this anyway? Shouldn't it becObject.getOwnPropertyNames(String.prototype)
?