View: array_key_exists

Function:
Description: Checks if the given key or index exists in the array.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
function array_key_exists (key, search) {
    // http://jsphp.co/jsphp/fn/view/array_key_exists
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
    // *     example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
    // *     returns 1: true
    // input sanitation
    if (!search || (search.constructor !== Array && search.constructor !== Object)) {
        return false;
    }

    return key in search;
}
Comment on array_key_exists version 20
Tests
Benchmark
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.