zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Ramda] Pluck & Props: Get the prop(s) from object array

amp The object from get Array Props prop
2023-09-14 09:00:53 时间

Pluck:

Get one prop from the object array:

R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2]
R.pluck(0)([[1, 2], [3, 4]]);   //=> [1, 3]

 

Props:

R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]

var fullName = R.compose(R.join(' '), R.props(['first', 'last']));
fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth'