简体   繁体   中英

Filter using Underscore.js

I need to filter the JSON above using Underscore.js

How can I return just the items that "Balance" is different from 0

 { Currency: 'BCC', Balance: 0, Available: 0, Pending: 0, CryptoAddress: null }, { Currency: 'BLOCK', Balance: 0, Available: 0, Pending: 0, CryptoAddress: 'Bd24akqYDG97k6xmUqsnxAtrBRoXeffQhx' }, { Currency: 'BTC', Balance: 0.00153928, Available: 0.00153928, Pending: 0, CryptoAddress: '1BgWkjF1mwe1MZoCvxMmfSJ6fppNMD5GSx' }, { Currency: 'BTG', Balance: 2e-8, Available: 2e-8, Pending: 0, CryptoAddress: null } 

Try this:

_.filter(yourList, function(obj){
   return obj.Balance !== 0
})

Here's a codepen example:

https://codepen.io/anon/pen/EbMRKY?editors=1111

let filtered = _.filter(transactions, (transaction) => {
 return transaction.Balance !== 0;
})

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