由值刪除陣列元素,以下是一個簡單的方式擴展 javascript prototype,試試!!
Array.prototype.remove = function(value){
const arr = [...this]
arr.splice(arr.indexOf(value), 1);
return arr;
}
const test = ['aaa','bbb','ccc']
let test2 = test.remove('bbb')
console.log(test2) // ['aaa','bbb']
Refrance:
https://stackoverflow.com/a/60989209/6784662
https://stackoverflow.com/a/10517081/6784662