Sunday 30 December 2018

Array.reduce is not a function?

Node 11.5I've got some very odd behavior cropping up when attempting to use an array of keys to create an object. This is something I've done many, many times before, and a minimum use case with the same code w/same data runs perfectly in Chrome..reduce is a function, but also not. What am I missing here?Error in Nodev11.5.0 [0] { id: 1, apple: 'pear', banana: 'orange' } [0] [ 'id', 'apple', 'banana' ] [0] function [0] function reduce() { [native code] } [0] true [0] Unhandled rejection TypeError: configKeys.reduce(...) is not a function Code That produced the errorlet defaultConfig = {id:1, apple:"pear", banana:"orange"} console.log(defaultConfig) const configKeys = Object.keys(defaultConfig) console.log(configKeys) console.log(typeof configKeys.reduce) console.log(configKeys.reduce.toString()) console.log(Array === configKeys.constructor) defaultConfig = configKeys.reduce(function(acc, key) { if(key !== 'id') { acc[key] = defaultConfig[key] } return acc }, {})

Submitted December 30, 2018 at 09:37PM by relativityboy

No comments:

Post a Comment