javascript - Is there a way to obtain index in array in more concise way? -


curiosity sponsors question, it's fun hack in languages.

assume there array holding objects of kind. objects have id property. id cannot empty string, false, null or falsey value. array can of 0 length. want obtain index of value (if present) , exit loop it's found.

var id = /some value check/; var index; (var = 0, item; item = arr[i],       item===undefined?false:item.id==id?(index=i,false):true; i++); 

what think?

meanwhile did jsperf posted above suggestions. please play around if want.

jsperf mentioned

fastest initial example above under ff , while loop posted in comments under chrome. find solution arrow functions slowest in both cases. cannot test in ie use no win.

i'm aware jsperf badly written - please play around.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -