Demo 1
Create new Javascript file named demo1.js. This file contains code demo as below:
var student = new Map();
student.set('id', 'st01');
student.set('name', 'Name 1');
student.set('age', 20);
console.log('Size: ' + student.size);
console.log('Name: ' + student.get('name'));
console.log('Check Id Key: ' + student.has('id'));
student.delete('age');
console.log('Size: ' + student.size);
student.clear();
console.log('Size: ' + student.size);
Run Demo 1
Use node demo1.js statement run code demo
Size: 3
Name: Name 1
Check Id Key: true
Size: 2
Size: 0
Demo 2
Create new Javascript file named demo2.js. This file contains code demo as below:
var student = new Map();
student.set('id', 'st01');
student.set('name', 'Name 1');
student.set('age', 20);
console.log('Student Info');
student.forEach((value, key) => {
console.log(key + ': ' + value);
});
let product = new Map([
['id', 'p01'],
['name', 'name 1'],
['price', 100]
]);
console.log('Product Info');
product.forEach((value, key) => {
console.log(key + ': ' + value);
});
Run Demo 2
Use node demo2.js statement run code demo
Student Info
id: st01
name: Name 1
age: 20
Product Info
id: p01
name: name 1
price: 100