[英]Is there something similar to lodash _.toArray for ramda.js?
I want to stop using lodash.js
and switch to ramda.js
but I don't see any function like _.toArray()
for objects, is there something like this in ramda
that I should compose or should I continue using lodash
for these functions (and possibly more cases that I have not run into yet.) 我想停止使用
lodash.js
并切换到ramda.js
但我没有看到像对象的_.toArray()
这样的函数, _.toArray()
是否存在这样的东西,我应该ramda
或者我应该继续使用lodash
这些函数(可能还有更多我尚未遇到的情况。)
For example In lodash
if you have an Object like : 例如,在
lodash
如果你有一个像这样的对象:
{"key1": {"inner": "val"}, "key2" : {"inner": "val"}}
you can convert it to an array like this: 你可以将它转换为这样的数组:
[{"inner": "val"}, {"inner": "val"}]
using the function _.toArray()
使用函数
_.toArray()
Well, Ramda has values
, which seems to be what you're looking for: 那么,Ramda具有
values
,这似乎是你在找什么:
var obj = {"key1": {"inner": "val"}, "key2" : {"inner": "val"}};
R.values(obj); //=> [{"inner": "val"}, {"inner": "val"}]
But it's pretty unclear from the lodash documentation , what kinds of values _.toArray
function accepts, so this might not be a complete replacement. 但是从lodash文档中可以很清楚地知道
_.toArray
函数接受什么类型的值,所以这可能不是完全替代。
Mb vanilla.js will help you? Mb vanilla.js会帮到你吗? :) ( browser support IE9+ and all other browsers )
:)(浏览器支持IE9 +和所有其他浏览器)
var obj = {"key1": {"inner": "val"}, "key2" : {"inner": "val"}}; var array = Object.keys(obj || {}).map(function(key){ return obj[key]; }); document.write(JSON.stringify(array, null, 4));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.