# find element in obj vs array (v42)

## Description

slightly better math

## Setup

``````var obj = {},
arr = [],
count = 0;
for (var i = 0; i < 10000; i++) {
arr.push('wowow124.23' + i);
obj['wowow124.23' + i] = 1;
}

function in_array(needle, haystack) {
var i = haystack.length
while (i--) {
if (haystack[i] == needle)
return true;
}
return false;
}
function in_array2(needle, haystack) {
for(i=haystack.length;i--;) {
if (haystack[i] == needle)
return true;
}
return false;
}

function include(needle, haystack) {
return (haystack.indexOf(needle) != -1);
}``````

## Test runner

Testing in
TestOps/sec
find in array1 (123)
``````if (in_array('wowow124.23123', arr)) {
count++;
}``````
find in array1 (1234)
``````if (in_array('wowow124.231234', arr)) {
count++;
}``````
find in array1 (9543)
``````if (in_array('wowow124.239543', arr)) {
count++;
}``````
find in array2 (123)
``````if (in_array2('wowow124.23123', arr)) {
count++;
}``````
find in array2 (1234)
``````if (in_array2('wowow124.231234', arr)) {
count++;
}``````
find in array2 (9543)
``````if (in_array2('wowow124.239543', arr)) {
count++;
}``````
indexOf in arr(123)
``````if (include('wowow124.23123', arr)) {
count++;
}``````
indexOf in arr(1234)
``````if (include('wowow124.231234', arr)) {
count++;
}``````
``````if (include('wowow124.239543', arr)) {