Set
The data structure is like an array, but there are no duplicate values in it
例1:set用法 let setArray=new Set(["a","b"]
result:
Example 2: setArray.add("a") adds an item to it
setArray.delete ("a") delete an item
setArray.has("a") Check if there is an item
result:
Example 3: set.clear() clears
result:
Example 4: Array deduplication
Result: [1,2,3,4,5,6,7]
Example 5: The set data structure becomes an array [...Set] I want Set to use the map loop and filter of the array
Result: {2,4,6}
Example 6:
result; {2,4,6}
Map
Similar to json but the key of json can only be a string
The key of the map can be of any type
Usage: let map=new Map(); set value
map.set(value,key);
Example 7:
result:
Get the value map.get(key); (Set does not have this method)
Delete an item map.delete(key);
Find if there is a certain value map.has(key);
clear map.clear()
Example 6:
result: