Let’s assume I have a huge (1000+) list of objects like this:
[{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
I want to filter this list by name (character wise).
filter('j') => [{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
filter('jo') => [{name: 'john dow', age: 38, gender:'m'}, ..]
filter('dow') => [{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
What is the highest performance way to do that? RegEx is obviously one of the keys, ordering the list beforehand if you assume that user usually tend to start names from the beginning may also a good idea, but it only helps in some cases.
Are there any JavaScript built-in functions for mapping a filter? I’d expect those to be faster than JavaScript implementations.
P.S.: Yes I want to filter on client side because of “offline capabilities” I want to offer.
Although a substring index (such as a Suffix tree) would make this faster, the direct search would be:
where
sis the query string andlis the list of objects.