TypeError: Object.entries is not a function

user7917402 picture user7917402 · May 9, 2017 · Viewed 38k times · Source

Why do I keep getting this error when trying to run my Node.js/Express server?

Is this a part of the newer ES7? What do I need to be able to run an app using these new features?

Answer

peja picture peja · Dec 26, 2017

On mdn docs, there is a clear tutorial on Object.entries, and it is described what to be done if Object.entries is not supported on part PolyFill in the same page.

To add compatible Object.entries support in older environments that do not natively support it, you can find a demonstrational implementation of Object.entries in the tc39/proposal-object-values-entries (if you don't need any support for IE), a polyfill in the es-shims/Object.entries repositories, or you can use the simple, ready to deploy polyfill listed below.

if (!Object.entries)
   Object.entries = function( obj ){
      var ownProps = Object.keys( obj ),
         i = ownProps.length,
         resArray = new Array(i); // preallocate the Array

      while (i--)
         resArray[i] = [ownProps[i], obj[ownProps[i]]];
      return resArray;
   };