Source array
arr1 = [1, 2, 3 , 4, 5]
modified
arr2 = [3, 4, 5 , 6, 7, 8, 9]
Increased? Deleted?
- Preoccupation 交集
const _arr1= new Set(arr1);
const _arr2 = new Set(arr2);
const someArr = [...new Set([..._arr1].filter(x => _arr2.has(x)))];
Arr1 array and the array is an array of the same arr2 someArr = [3, 4, 5]
After finding the modifications added and deleted
- deleted
const deleteArr = [];
arr1.map((item) => {
if (someArr.indexOf(item) === -1) {
deleteArr.push(item);
}
});
- Increased
arr2.map((item) => {
if (someArr.indexOf(item) === -1) {
addArr.push(item);
}
});