Useful JavaScript's methods in LWC and Lightning Component - Part II

Updated: Mar 18, 2020

Map in JavaScript


1. Define a map in LWC and Aura Component -


let map1 = new Map([[1 , "Saurabh"], [2 , "Supriya"] ,[3, "Yuvraj"]]); 
console.log(map1.get(1)); // print Saurabh

2. get(key) - fetch value by key


console.log(map1.get(1)); // print Saurabh

3. set(key,value) - adds key and value to map.


map1.set(4, "ABCD");

4. has(key) - Check whether map contains key.


if(map1.has(3