-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_array().txt
More file actions
32 lines (31 loc) · 957 Bytes
/
Copy pathin_array().txt
File metadata and controls
32 lines (31 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// JS equivalent of PHP's in_array
function in_array (needle, haystack, argStrict)
{
// * example 1: in_array('van', ['Win', 'van', 'hello World']);
// * returns 1: true
// * example 2: in_array('work', {0:'Win', work:'van', 1:'World'});
// * returns 2: false
// * example 3: in_array(1, ['1', '2', '3']);
// * returns 3: true
// * example 3: in_array(1, ['1', '2', '3'], false);
// * returns 3: true
// * example 4: in_array(1, ['1', '2', '3'], true);
// * returns 4: false
var key = '', strict = !!argStrict;
if (strict)
{
for (key in haystack) {
if (haystack[key] === needle) {
return true;
}
}
} else
{
for (key in haystack) {
if (haystack[key] == needle) {
return true;
}
}
}
return false;
}//end func...