简体   繁体   English

是否有类似于lodash _.toArray的ramda.js?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM