Skip to content
Advertisement

Got undefined in map result

I’m having trouble converting, summing, and sorting the following arrays into key and value objects

Data Array

JavaScript

my current code

JavaScript

and the result of my current code

JavaScript

though, the result I want is like this

JavaScript

Advertisement

Answer

Map.prototype.set() only takes 2 arguments, you’re passing 3. If you want to store multiple values in a map key, store them as an array or object. In my code below, I store [price, url].

Another problem is that you were trying to parse curr["Product Name"] as the price, but it should be curr.Price.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement