lowdb
lowdb copied to clipboard
How to remove all items in an array
hi all,
I have this use to remove all items from an array.
Later I found that it is available in lodash library.
you can remove all items from an array by
db.get('users').find({username: token.username}).get('recentMovies').remove( (item) => true).write();
'recentMovies' is an array in my case.
Note: I am returning true always for all the items, you can programmatically do that also. .remove( (item) => true)
Can you not just use set?
db.get('users').find({username: token.username}).set('recentMovies', []).write();