javascript key, value map code example
Example 1: map through keys javascript
var myObject = { 'a': 1, 'b': 2, 'c': 3 };
Object.keys(myObject).map(function(key, index) {
myObject[key] *= 2;
});
console.log(myObject);
Example 2: javascript object entries
const object1 = {
a: 'somestring',
b: 42
}
Object.entries(object1)
.forEach(([key, value]) => console.log(`${key}: ${value}`))
Example 3: js object keys
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);
Example 4: object.keys
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
Example 5: javascript map
array.map((item) => {
return item * 2
}
Example 6: javascript map
function listFruits() {
let fruits = ["apple", "cherry", "pear"]
fruits.map((fruit, index) => {
console.log(index, fruit)
})
}
listFruits()