简体   繁体   中英

Ramda.js how to pluck with digging object

I want to make an array which have items of id.

Here is my code.

 const list = [ { meta: { id: 0 } }, { meta: { id: 1 } } ] const result = R.pluck('id')(R.pluck('meta')(list)) // → [0, 1] console.log(result);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.min.js"></script>

I am doing pluck twice and I think this is not cool.

Any coolest way to do this?

I want to use Ramda.js.

Word around town is that this is pretty cool:

 const list = [ { meta: { id: 0 } }, { meta: { id: 1 } } ] const result = R.map(R.path(['meta', 'id']))(list); console.log(result);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.min.js"></script>

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