ArrayedCollection method 'indexOf' doesn't match strings

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ArrayedCollection method 'indexOf' doesn't match strings

Graham Booth
Hi all,

I'm having a problem locating the index of an item in array, using .indexOf, when the array is made up of strings.

For example...

[1, 2, 3].indexOf(2);

...works fine, but:

["one", "two", "three"].indexOf("two");

...just returns nil.

Any ideas? Am I missing something obvious? I could iterate over the array using do or collect to pull out the index, but that seems like overkill.

Graham.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ArrayedCollection method 'indexOf' doesn't match strings

Mosquito netting
Thank you for sharring . This is the knowledge I need search
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ArrayedCollection method 'indexOf' doesn't match strings

soh_la
In reply to this post by Graham Booth
You can use indexOfEqual to check if the item is equal.
Loading...