javascript Immutablejs:将地图的键转换为数组的一行代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30002578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:28:22 来源:igfitidea点击:
Immutablejs: One liner code to convert keys of a map into array?
提问by Melvin
回答by OlliM
回答by geeklain
If you can use ES6:
如果您可以使用 ES6:
var map = Immutable.fromJS({
a: 1,
b: 2,
c: {
d: "asdf"
}
});
var [...arr] = map.keys();
console.log(arr); // ["a", "b", "c"]
Or
或者
var arr = Array.from(map.keys());
console.log(arr); // ["a", "b", "c"]