Filtering collections is a good idea when you're not exactly sure what you'll find. At other times, you know that there's exactly one collection value needed. The problem with filtering is that the entire collection is searched no matter what. When you try to find a single item, the search ends with the first match.
There are different types of existence checks that you can perform, depending on the type of collection. If it's a list, it's an indexed collection, which means that you can check for the existence of a specific index. If it's a map, it's a keyed collection, which means that you can check for the existence of a specific key. You can also check for the existence of a value in either collection type.
Let's create a list and check for some indexes, as follows:
const myList = List.of(1, 2, 3); const myListHas2 = myList.has(2); const myListHas3 = myList.has(3); console.log('myListHas2', myListHas2); // -> myListHas2 true console.log...