+ 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

2nd Nov 2019, 8:15 PM
Ade Bakari
Ade Bakari - avatar
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
2nd Nov 2019, 8:32 PM
Ryan
Ryan - avatar
+ 1
The let result at the bottom is what I have tried so far
2nd Nov 2019, 8:17 PM
Ade Bakari
Ade Bakari - avatar
+ 1
Thanks, why is is a.country_represented?
2nd Nov 2019, 8:38 PM
Ade Bakari
Ade Bakari - avatar
+ 1
Instead of data.
2nd Nov 2019, 8:38 PM
Ade Bakari
Ade Bakari - avatar
+ 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).
2nd Nov 2019, 8:46 PM
Ryan
Ryan - avatar
+ 1
thanks, part 2 of that task is I need to make it into one string. working on that now
2nd Nov 2019, 9:31 PM
Ade Bakari
Ade Bakari - avatar