The way JS collections store values

this.add = function(value) {
  if(!this.has(value)){
    items[value]=value;
    return true;
  }
  return false;
}
for this line of code: items [value] = value , the book says: when you add a value, save it as both a key and a value, which helps to find the value .
< H2 > question: how does it help to find this value in this way? Is it advantageous to use the value to find the value? What"s wrong with passing a button? < / H2 >
Mar.01,2021

look at the application scenario. Sometimes value itself is suitable as a key, which is easy to find. In other cases, it is not easy to find an attribute in value that can be used as a key, so you might as well use it as a key.


how to pass the key add (value) is not add (key,value) say that the front leg of this sentence is the add method that simulates set

Menu