Chrome DevTools-Console 评估中的“推送”是什么意思?

问题描述

当我在 Chrome DevTools - Console 中评估一个特定变量时,结果如下:

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

我知道 f 的意思是,数组包含一个函数

push 这个词在这种情况下代表什么?

解决方法

表示有人在数组中添加了自定义属性。这不是标准的 Array.prototype.push,而是别的东西。

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

enter image description here

如果有标准的 .push,它就不会出现在控制台中。

(在专业代码中尽量避免这种情况。这很奇怪。)