// new Map([iterable]) let recipeMap = newMap([ ['Cucumber', '500 gr'], ['Tomatoes', '350 gr'], ]); // Sets the value for the key in the Map object. Returns the Map object. recipeMap = recipeMap.set('Sour cream', '50 gr'); // Returns a boolean asserting whether a value has been associated to the key in the Map object or not. console.log(recipeMap.has('Cucumber')); // true // loop by keys for(let fruit of recipeMap.keys()) { console.log(fruit); // Cucumber // Tomatoes // Sour cream } // loop by values [key, value] for(let amount of recipeMap.values()) { console.log(amount); // 500 gr // 350 gr // 50 gr } // loop by recoeds for(let entry of recipeMap) { // same like recipeMap.entries() console.log(entry); // ["Cucumber", "500 gr"] // ["Tomatoes", "350 gr"] // ["Sour cream", "50 gr"] } // Returns true if an element in the Map object existed and has been removed, or false if the element does not exist. console.log(recipeMap.delete('paopaolee')); // false // Removes all key/value pairs from the Map object. recipeMap.clear(); // Returns the number of key/value pairs in the Map object. console.log(recipeMap.size === 0); // True
const planetsOrderFromSun = newSet(); planetsOrderFromSun.add('Mercury'); planetsOrderFromSun.add('Venus').add('Earth').add('Mars'); // Chainable Method console.log(planetsOrderFromSun.has('Earth')); // True planetsOrderFromSun.delete('Mars'); console.log(planetsOrderFromSun.has('Mars')); // False for (const x of planetsOrderFromSun) { console.log(x); // Same order in as out - Mercury Venus Earth } console.log(planetsOrderFromSun.size); // 3 planetsOrderFromSun.add('Venus'); // Trying to add a duplicate console.log(planetsOrderFromSun.size); // Still 3, Did not add the duplicate planetsOrderFromSun.clear(); console.log(planetsOrderFromSun.size); // 0
var ws = newWeakSet(); var foo = {}; var bar = {}; ws.add(foo); ws.add(bar); ws.has(foo); // true ws.has(bar); // true ws.delete(foo); // removes foo from the set ws.has(foo); // false, foo has been removed