从数组中删除所有匹配的元素
我有这个数组:
["onelolone", "twololtwo", "three"]
如何删除仅用'lol'作值的元素,结果是:
["three"]
回答
使用Array.prototype.filter,并检查它是否不包括"lol":
const result = ["onelolone","twololtwo","three"].filter(ele => !ele.includes("lol"))
console.log(result)// ["three"]