UNPKG

locutus

Version:

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

19 lines (18 loc) 818 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.array_fill_keys = array_fill_keys; const _phpTypes_ts_1 = require("../_helpers/_phpTypes.js"); function array_fill_keys(keys, value) { // discuss at: https://locutus.io/php/array_fill_keys/ // original by: Brett Zamir (https://brett-zamir.me) // bugfixed by: Brett Zamir (https://brett-zamir.me) // example 1: var $keys = {'a': 'foo', 2: 5, 3: 10, 4: 'bar'} // example 1: array_fill_keys($keys, 'banana') // returns 1: {"foo": "banana", 5: "banana", 10: "banana", "bar": "banana"} const retObj = {}; const keyedValues = (0, _phpTypes_ts_1.toPhpArrayObject)(keys); for (const keyedValue of Object.values(keyedValues)) { retObj[String(keyedValue)] = value; } return retObj; }