Which is more accurate/cross-browser compatible?
Example 1
if(!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
};
}
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
Example 2
function isInArray(arr,str) {
return (arr.indexOf(str) != -1);
}
-I lost the source-
They do completely different things.
The first tests to see if something is an array. The second tests to see if an array contains a given object.