SO-75850878
by David Thomas
JavaScript
// the initial arrays:
let keys = [ 'J', 'o', 'h', 'a', 'n'],
entries = [ 1, 1, 1, 2, 1],
// here we use Object.fromEntries() to create
// an Object from a two-dimensional Array of
// Arrays:
result = Object.fromEntries(
// we use Array.prototype.map() to iterate over
// the keys Array:
keys.map(
// passing a reference to the current Array-value
// ('key'), and the index of the current Array-
// value ('index') into the function body.
// Within the function body we return an Array
// containing the current Array-element (which
// becomes a key of the created-Object, and
// the Array-element from the entries Array
// at the same index:
(key, index) => [key,entries[index]]
));
console.log(result);
/*
{
"J": 1,
"o": 1,
"h": 1,
"a": 2,
"n": 1
}
*/