blob: 0fc597736b2cfa061711ed5846ad53bc5caff89c (
plain) (
blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
'use strict';
module.exports = function key(arr) {
// discuss at: http://locutus.io/php/key/
// original by: Brett Zamir (http://brett-zamir.me)
// input by: Riddler (http://www.frontierwebdev.com/)
// bugfixed by: Brett Zamir (http://brett-zamir.me)
// note 1: Uses global: locutus to store the array pointer
// example 1: var $array = {fruit1: 'apple', 'fruit2': 'orange'}
// example 1: key($array)
// returns 1: 'fruit1'
var $global = typeof window !== 'undefined' ? window : global;
$global.$locutus = $global.$locutus || {};
var $locutus = $global.$locutus;
$locutus.php = $locutus.php || {};
$locutus.php.pointers = $locutus.php.pointers || [];
var pointers = $locutus.php.pointers;
var indexOf = function indexOf(value) {
for (var i = 0, length = this.length; i < length; i++) {
if (this[i] === value) {
return i;
}
}
return -1;
};
if (!pointers.indexOf) {
pointers.indexOf = indexOf;
}
if (pointers.indexOf(arr) === -1) {
pointers.push(arr, 0);
}
var cursor = pointers[pointers.indexOf(arr) + 1];
if (Object.prototype.toString.call(arr) !== '[object Array]') {
var ct = 0;
for (var k in arr) {
if (ct === cursor) {
return k;
}
ct++;
}
// Empty
return false;
}
if (arr.length === 0) {
return false;
}
return cursor;
};
//# sourceMappingURL=key.js.map
|