September 2017
Intermediate to advanced
216 pages
6h 8m
English
If there's a specific value you're looking for, starting from the end of the list and moving toward the beginning of it, you can use the findLast() method, as follows:
const myList = List.of('apples', 'bananas', 'cherries', 'chocolate');const predicate = s => s.startsWith('ch');const myFoundItem = myList.findLast(predicate);console.log('myList', myList.toJS());// -> myList [ 'apples', 'bananas', 'cherries', 'chocolate' ]console.log('myFoundItem', myFoundItem);// -> myFoundItem chocolate
As it turns out, the predicate() function finds a value at the very end of this list. Since you're starting at the end and moving left, no other values are checked. Let's use predicate() to perform a filter from the right: ...
Read now
Unlock full access