gpt4 book ai didi

javascript - 从数组中删除所有匹配的元素

转载 作者:行者123 更新时间:2023-12-02 16:20:50 25 4
gpt4 key购买 nike

我有这个数组:

["onelolone", "twololtwo", "three"]

如何删除仅使用 'lol' 作为值的元素,结果是:

["three"]

最佳答案

使用Array.prototype.filter ,并检查它是否不包含 "lol":

const result = ["onelolone","twololtwo","three"].filter(ele => !ele.includes("lol"))

console.log(result)// ["three"]

关于javascript - 从数组中删除所有匹配的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65556199/

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