JavaScript: difference in efficiency of indexOf method on String and Array -
i curious whether there exists difference in efficiency indexof method available both array , string in javascript. thought indexof less efficient on string on array, , new testing results support this. example: var arr = ['abc', 'ab', 'abz', '1']; var str = 'abcababz1'; var needle = 'abxx'; //concatenate make them bigger (var = 0; < 30; i++) { arr = arr.concat(arr); str = str.concat(str); } arr.push(needle); //append needle last str = str.concat(needle); then used start , end timestamp arr.indexof(needle); // faster! str.indexof(needle); i did testing in node, new testing results showed: time used on array is: 35 time used on string is: 57 so array more efficient indexof string. new testing creates worst case scenario -- needle @ end of string or array. edit: if indexof more efficient on array, wondering if should first split string (delimited comma, example) array before using indexof method se...