UNPKG

locutus

Version:

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

19 lines (18 loc) 597 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.array_shift = array_shift; function array_shift(inputArr) { // discuss at: https://locutus.io/php/array_shift/ // original by: Kevin van Zonneveld (https://kvz.io) // improved by: Martijn Wieringa // note 1: Currently does not handle objects // example 1: array_shift(['Kevin', 'van', 'Zonneveld']) // returns 1: 'Kevin' if (inputArr.length === 0) { return null; } if (inputArr.length > 0) { return inputArr.shift() ?? null; } return null; }