i want to have reusable function that maps an array of objects based on property passed as parameter to function.
Here's my code:
let arr = [
{
country: 'poland',
population: 380000
},
{
country: 'bangladesh',
population: 3492423
}
]
function filterMyArr (myArr, condition) {
return myArr.map(element => element.country)
}
console.log(filterMyArr(arr))
When i change code and try to pass condition, while executing it doesn't work. I want to call a function with second parameter for example filterMyArr(arr, country) and to have similar outcome. I want it to be reusable so i can use it for population or any other property. Thank you.