gpt4 book ai didi

javascript - [].forEach.call(...?

转载 作者:数据小太阳 更新时间:2023-10-29 05:04:58 27 4
gpt4 key购买 nike

我非常喜欢像这样在 nodeLists 上使用 forEach 方法:

var nodes = document.querySelectorAll(".foo");

[].forEach.call(nodes, function (item) {
//do stuff with item
});

不过我想知道,这样做是否比常规方式需要更长的时间?例如

for(var i=0;i<nodes.length;i++){
//do stuff with nodes[i];
}

最佳答案

这是一个 nice performance comparison .根据它,Array.forEach 比本地 for 循环慢。

关于javascript - [].forEach.call(...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2317426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com