+ 1
how to extract property from object in Array
The task I was given is to, extract countries as a comma-separated values string i.e. and console.log it https://code.sololearn.com/WmvmH0DBVcA6/?ref=app
6 Answers
+ 2
From the looks of it, it seems that you don't know how to use the "map" method.
Here's a resource that helps you learn more about the "map" method: https://www.w3schools.com/jsref/jsref_map.asp
Here's a fixed version of your code:
https://code.sololearn.com/Wu6BDdGd4EM7/?ref=app
+ 1
The let result at the bottom is what I have tried so far
+ 1
Thanks, why is is a.country_represented?
+ 1
Instead of data.
+ 1
Because the "a" is the object inside the array and I simply accessed the "country_represented" property.
The "map" method lets you loop over an array's elements and it takes a function as an argument.
The first parameter of that function represents the the element inside the array(in this case an object).
+ 1
thanks,
part 2 of that task is I need to make it into one string. working on that now