Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Javascript 中有地图/字典:
var m = { dog: "Pluto", duck: "Donald" };
我知道如何获取键Object.keys(m),但是如何获取对象的值?
Object.keys(m)
您只需遍历键并检索每个值:
var values = []; for (var key in m) { values.push(m[key]); } // values == ["Pluto", "Donald"]
没有类似的功能,但您可以使用:
var v = Object.keys(m).map(function(key){ return m[key]; });