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
  • 50,146
  • 13
  • 101
  • 111
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
  • 683,504
  • 96
  • 985
  • 979
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