1. Add
Two methods of adding elements to an array (neither deduplication)
1. Array.push(object)
Append new elements directly to the end of the array (without deduplication)
//this.productTemporary=[]
this.productTemporary.push(e);
When using push to add an array, the entire array will be directly added to the array
1. Array.concat(object)
Using concat will split the data (array) to be appended to append to the end of the data
//this.products=[]
this.products = this.products.concat(res.result.items); //追加新数据
Append the same data
Append a group of arrays
3. Array deduplication
//arr:需要被去重的数组
res = new Map();
v = arr.filter(arr => !res.has(arr.productId) && res.set(arr.productId, arr.productId));
Two, delete
1. Use splice to delete elements
Delete the elements in the array (delete by finding the subscript of the object); index ==-1 means the array is empty
// this.productTemporary数组
//item需要删除的元素
const index = this.productTemporary.findIndex(i => i == item)
if (index != -1) {
this.productTemporary.splice(index, 1)
}