object values map javascript code example

Example 1: javascript object entries

// Object Entries returns object as Array of [key,value] Array
const object1 = {
  a: 'somestring',
  b: 42
}
Object.entries(object1) // Array(2) [["a", "something"], ["b", 42]]
  .forEach(([key, value]) => console.log(`${key}: ${value}`))
// "a: somestring"
// "b: 42"

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}); //=> {x: 2, y: 4, z: 6}

Example 3: object to map javascript

const map = new Map(Object.entries({foo: 'bar'}));

map.get('foo'); // 'bar'

Example 4: key value in map JavaScript mapping object

const map = {"a": 1, "b": 2, "c": 3};
const mapped = Object.entries(map).map(([k,v]) => `${k}_${v}`);
console.log(mapped);