map on object js code example
Example 1: map object es6
var myObject = { 'a': 1, 'b': 2, 'c': 3 };
Object.keys(myObject).map(function(key, index) {
myObject[key] *= 2;
});
console.log(myObject);
Example 2: js map on object
import { map } from "ramda"
const double = x => x * 2;
const mappedObject = map(double, {x: 1, y: 2, z: 3});
Example 3: map in javascript
const arr = [1,2,3,4]
const sqrs = arr.map((num) => num ** 2)
console.log(sqrs)
console.log(arr)
Example 4: map through keys javascript
var myObject = { 'a': 1, 'b': 2, 'c': 3 };
for (var key in myObject) {
if (myObject.hasOwnProperty(key)) {
myObject[key] *= 2;
}
}
console.log(myObject);
Example 5: 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);