A
A
Andrey Dyrkov2016-04-24 21:08:04
JavaScript
Andrey Dyrkov, 2016-04-24 21:08:04

What is the best way to search in an array?

There is an array
var array = ['меню',...];
I need to find all elements starting with a string. Suppose for "a" all words starting with "a", then all beginning with "arb", then all with "watermelon". Going through all the elements in an array for a match is not very cool, how best to organize this? I would like to find an efficient solution. I can make any structrute out of an array if needed :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-04-24
@VIKINGVyksa

In theory, it would be ideal to build a prefix tree. Here, here the Khabrovchanin explains: https://habrahabr.ru/post/111874/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question