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

我有这个数组:

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

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

["three"]

回答

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

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

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


以上是从数组中删除所有匹配的元素的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>