1 person found this helpful
...you can call myArray.findIndex("element") written on February 2, 2006
---> doesn't work today (findIndex is not a function)
...you can call toString(myArray).indexOf("element") written on Dec 18, 2009
---> doesn't work today. Result == -1 cause toString(myArray) gives a string "[object Global]"
That depends on the kind of objects that are stored in myArray. Not everything can be fed into toString.
I know I can use statement for and catch index comparing myArray elements step by step, however...
Nothing wrong with that. It Just So Happens there is no built-in function, which should not put you off right from the start. In fact, at times I have found myself writing a function for something that was built-in after all.
Okay. With that out of the way: much -- a lot, or perhaps everything -- depends on the type of your array objects and on what you intend to find. For example, if it's lots of text strings and you need to be able to find any one as fast as possible, you could sort them and use a binary search.