1

I'm studying the difference between Object.method and Object.prototype.method. I know I should use Object.keys() as following.

    var arr = new Array(1,2,3);
    console.log(Object.keys(arr)); //["0", "1", "2"]

and Object.prototype.toString() as following

var arr = new Array(1,2,3);
arr.toString(); // "1,2,3"
console.log(arr.keys(arr));

I get

Array Iterator {}

at a console. Why? Shouldn't it be denied in the first place? (Since .keys() method is in Object object itself not in Object.prototype that maybe means arr cannot approach to the .keys() method?) What am I missing?

0

1 Answer 1

6

You actually found another method, namely Array.prototype.keys()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.