How to use Object.values() on server side in Node.js

前端 未结 7 1368
不思量自难忘°
不思量自难忘° 2020-12-03 00:46

Object.values() received following error:

TypeError: Object.values is not a function.

From this question on stack

7条回答
  •  星月不相逢
    2020-12-03 01:13

    Here's a polyfill that kicks in only when it's not already defined:

    const objectToValuesPolyfill = (object) => {
      return Object.keys(object).map(key => object[key]);
    };
    Object.values = Object.values || objectToValuesPolyfill;
    

提交回复
热议问题