.values is unsupported in many browsers - you can use .map to get an array of all the values:
var vals = Object.keys(countries).map(function(key) {
return countries[key];
});
See MDN doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values or Official doc: https://tc39.github.io/ecma262/#sec-object.values (thanks @evolutionxbox for correction)
Answer from tymeJV on Stack Overflow.values is unsupported in many browsers - you can use .map to get an array of all the values:
var vals = Object.keys(countries).map(function(key) {
return countries[key];
});
See MDN doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values or Official doc: https://tc39.github.io/ecma262/#sec-object.values (thanks @evolutionxbox for correction)
It's also worth noting that only Node versions >= 7.0.0 fully support this.
http://node.green
node.js - Uncaught TypeError: Object.values is not a function - Stack Overflow
"TypeError: Object.values is not a function" on Node 6
TypeError: Object.values is not a function
node.js - Object.values is not a function error - Stack Overflow
Object.values is a new feature in ES2017. It is very bleeding edge. Node.js has full support for it from version 7.0.
6.8.1 supports it, but it is considered unstable and is locked behind the --harmony flag.
You can either:
- Upgrade to the latest Node.js LTS and use
--harmony - Upgrade to the latest Node.js Current
- Use a polyfill
Object.values() is in status "Draft" for the version ECMAScript2017 and here the specification: ECMAScript 2017 Draft (ECMA-262) The definition of 'Object.values' in that specification..
The Object.values() method returns an array of a given object's own enumerable property values, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
Without change nothing in your NodeJS enviroment you can achive the same by using Object.keys() that returns an array of keys and chaining a Array.prototype.map() method to return the desired array of the Object's values:
const obj = {
foo: "bar",
baz: 42
},
// Object.values()
objValues = Object.values(obj),
// Object.keys() and map(),
objKeysMap = Object.keys(obj).map((k) => obj[k]);
console.log('objValues:', objValues);
console.log('objKeysMap:', objKeysMap);
Run code snippetEdit code snippet Hide Results Copy to answer Expand
Samsung's TizenOS's javascript isn't as up-to-date as it could be, and according to this looks to not be actively supported.
You can use react-app-polyfill to provide any missing functionalities.
We use the following in our root index.jsx as the "kitchen sink" of polyfills
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';
It seems Object.values() is not supported in your developing environment. Try adding this polyfill on top of your script file: https://github.com/tc39/proposal-object-values-entries/blob/master/polyfill.js
Hello,
While working in React I made an ES6 arrow function. When I saved my work and the app automatically reloaded in Chrome, I got a gray screen with the following message:
TypeError: Object(...) is not a function
When I converted the arrow function to an ES5 function, the error did not appear anymore. For example if I would have something similar to this it would error out:
const setLocale = (locale) => {
localStorage.setItem('locale', locale);
}
But if I had the function like this, no error would be thrown:
function setLocale (locale) {
localStorage.setItem('locale', locale);
}
Is there a particular reason why arrow functions cause these errors in React, but ES5 functions do not? I have tried Googling this issue, but was not able to find an answer.
Any help is appreciated.
Thanks