简体   繁体   中英

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.)

For example In lodash if you have an Object like :

{"key1": {"inner": "val"}, "key2" : {"inner": "val"}}

you can convert it to an array like this:

[{"inner": "val"}, {"inner": "val"}]

using the function _.toArray()

Well, Ramda has values , which seems to be what you're looking for:

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.

Mb vanilla.js will help you? :) ( browser support IE9+ and all other browsers )

 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)); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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