JS ‐ Helpful Codes - deptster/deptster.github.io GitHub Wiki
To enable copy-paste in web browser
e. stoplmmediatepropagation ( )
}
document.addEventListener (
"paste",
dontTreadOnMe,
true
);
Convert JSON into a Map in JS
contactRec = Your JSON data;
const jsonMap = new Map();
for (const key in contactRec) {
jsonMap.set(key, contactRec[key]);
}
// Now your JSON data has been converted into a map object
console.log(jsonMap);
If you want to access and Manipulate the data in the map you can do the following:
Case 1: To access the value in a specific key and to check if it exists or not
console.log(jsonMap.get('key1'));
console.log(jsonMap.has('key2'));
Case 2: If you want to replace all the null values to "No Data"
jsonMap.forEach((value, key) => {
if(value == null) {
jsonMap.set(key, "No Data");
}
});