UNPKG

locutus

Version:

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

19 lines (18 loc) 767 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.array_key_last = array_key_last; const _phpTypes_ts_1 = require("../_helpers/_phpTypes.js"); function array_key_last(input) { // discuss at: https://locutus.io/php/array_key_last/ // parity verified: PHP 8.3 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: array_key_last({ a: 1, b: 2 }) // returns 1: 'b' // example 2: array_key_last(['x', 'y']) // returns 2: 1 // example 3: array_key_last([]) // returns 3: null const keys = Object.keys(input); const lastKey = keys.at(-1); return typeof lastKey === 'string' ? (0, _phpTypes_ts_1.normalizeArrayKey)(lastKey) : null; }