[Solved] How do you convert a javascript array into an object? [closed]


 Array.prototype.toObject  = function(){
   // var length = this.length - 1;
   return this.reduce(function(obj, val, index, array) {
      if(index %2 != 0) return obj;
      // if(index == length) return obj; // leave the 'e' property
      obj[val] = array[index+1];
      return obj;
   }, {})
 }
 
 
var a = ['a', 'b', 'c','d', 'e', 'f'];
console.log(a.toObject());

solved How do you convert a javascript array into an object? [closed]