Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Ramda remove to remove empty object from Array of objects?

Ramda remove : Ramda Repl link

The following is the given example, it removes specific numbers from an Array:

R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]

Now I created an Array of objects, one being empty:

var objArray = [{id: 1, name: 'Leon'},{id: 2, name: 'Paulo'},{}];

When I try:

R.remove({}, objArray);

or

R.remove(R.isEmpty, objArray);

It returns a function:

enter image description here

Why would that be you suppose?

like image 654
Leon Gaban Avatar asked Jan 04 '23 13:01

Leon Gaban


1 Answers

Figured it out:

const filteredAlerts = R.filter(Util.notEmpty, res.alerts);

I needed to filter by objects that are NOT empty.

This is my Util.notEmpty function:

const notEmpty = R.compose(R.not, R.isEmpty);

like image 58
Leon Gaban Avatar answered Jan 07 '23 03:01

Leon Gaban