1

I have map/dictionary in Javascript:

var m = {
   dog: "Pluto",
   duck: "Donald"
};

I know how to get the keys with Object.keys(m), but how to get the values of the Object?

Ian
  • 48,619
  • 13
  • 99
  • 109
Markus
  • 23
  • 7

2 Answers2

2

You just iterate over the keys and retrieve each value:

var values = [];
for (var key in m) {
    values.push(m[key]);
}
// values == ["Pluto", "Donald"]
jfriend00
  • 637,040
  • 88
  • 896
  • 906
1

There is no similar function for that but you can use:

var v = Object.keys(m).map(function(key){
    return m[key];
});
Ana
  • 163
  • 5