new Map() javascript code example
Example 1: js map constructor
let myMap = new Map([
[1, 'one'],
[2, 'two'],
[3, 'three'],
])
Example 2: javascript map
array.map((item) => {
return item * 2
}
Example 3: initialize a map js
let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'
console.log(map)
Example 4: new map js
let utilisateurs = new Map()
utilisateurs.set('Mark Zuckerberg' ,{
email: '[email protected]',
poste: 'PDG',
})
utilisateurs.set ('bill Gates',{
email: '[email protected]' ,
poste : 'sauver le monde' ,
})
console.log(utilisateurs);
Example 5: map in js
const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
let inside_data = data.brands.map((i) => {
console.log(i);
});
Example 6: javascript map
The map() method creates a new array with the results of calling a provided function on every element in the calling array.