gpt4 book ai didi

javascript - 如何删除 map() 中的重复项

转载 作者:行者123 更新时间:2023-11-30 10:59:08 24 4
gpt4 key购买 nike

如何删除 [].map() 中的重复项。 a.href 可能包含相同的 href 链接,我怎样才能停止这种重复出现的数据?示例:www.example.com | www.example.com

const hrefs = await page.evaluate(() => {
const anchors = document.querySelectorAll('a');
return [].map.call(anchors, a => a.href);
});

最佳答案

Set hrefs = new Set([].map.call(anchors, a => a.href));
return [...hrefs];

关于javascript - 如何删除 map() 中的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58652967/

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