UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

22 lines (21 loc) 910 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.key = key; const _arrayPointers_ts_1 = require("../_helpers/_arrayPointers.js"); function key(arr) { // discuss at: https://locutus.io/php/key/ // parity verified: PHP 8.3 // original by: Brett Zamir (https://brett-zamir.me) // input by: Riddler (https://www.frontierwebdev.com/) // bugfixed by: Brett Zamir (https://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' const state = (0, _arrayPointers_ts_1.getPointerState)(arr, true); if (!state) { return false; } const entry = (0, _arrayPointers_ts_1.getEntryAtCursor)(arr, state.cursor); return entry ? entry[0] : false; }