Julian
Julian

Reputation: 84

What does "push" mean in evaluation of Chrome DevTools-Console?

When I evaluate one specific variable in Chrome DevTools - Console, this is the result:

(3) [Array(2), Array(2), Array(2), push: ƒ]

I know the f means, the array contains a function.

What does the word push stand for in this context?

Upvotes: 1

Views: 127

Answers (1)

Snow
Snow

Reputation: 4097

It means that someone has added a custom property to the array. It's not the standard Array.prototype.push, it's something else.

const arr = [1, 2];
arr.push = () => 'some custom implementation';
console.log(arr);

enter image description here

If the standard .push was there, it wouldn't be showing up in the console.

(Try to avoid this in professional code. It's weird.)

Upvotes: 4

Related Questions