JSFiddle - React, Tailwind, and code Playground
HTML
<div id="results"></div>
JavaScript
Array.prototype.toObject = function(keys){
var obj = {};
var tmp = this; // we want the original array intact.
if(keys.length == this.length)
while(tmp.length)
obj[keys.shift()] = tmp.shift();
return obj;
};
var values = ["cheese","paint", 14, 8];
var keys = [0,"onion",4,99];
var result = values.toObject(keys);
document.getElementById('results').innerHTML = 'values array length: ' + values.length + '; keys array length: ' + keys.length;