Procura de valores em array
Enviado por Flavio Ribeiro, ter, 23/12/2008 - 03:59
function in_array(needle, haystack, strict) {
// Checks if the given value exists in the array
//
// version: 810.114
// + original by: Kevin van Zonneveld
// * example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
// * returns 1: true
var found = false, key, strict = !!strict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}
}
return found;
}
»
- Comentar
- 362 leituras
