js .map in .map code example
Example 1: functions in map javascript
const map = new Map();
function foo() {
return "Hello World!";
}
map.set("foo", foo);
console.log(map.get("foo")()); // Output: "Hello World!
Example 2: .map in js
// A function which returns the last character of a given string
function returnLast(arr) {
return arr.at(-1);
}
let invoiceRef = 'myinvoice01';
console.log( returnLast(invoiceRef) );
// Logs: '1'
invoiceRef = 'myinvoice02';
console.log( returnLast(invoiceRef) );
// Logs: '2'