Is there a native method in JavaScript for mapping over objects, similar to Array.prototype.map? I have an object like this:
myObject = { 'a': 1, 'b': 2, 'c': 3 };
I want to create a new object using a function that processes each key-value pair, like so:
newObject = myObject.map(function (value, label) {
return value * value;
});
// newObject should be { 'a': 1, 'b': 4, 'c': 9 };
Does JavaScript provide a map function for objects? (I’m using Node.js, so cross-browser compatibility isn’t a concern.)
I’m looking for guidance on using javascript map object techniques to achieve this.