UNPKG

locutus

Version:

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

16 lines (15 loc) 687 B
import { toPhpArrayObject, } from "../_helpers/_phpTypes.js"; export 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 = toPhpArrayObject(keys); for (const keyedValue of Object.values(keyedValues)) { retObj[String(keyedValue)] = value; } return retObj; }