I have array
const arr = [
{id: 1, country: 'Austria'},
{id: 2, country: 'Germany'},
{id: 3, country: 'Austria'},
];
I tried the following the code to filter it.
arry.map((item,idx) => (
item.country== "Austria"?(
console.log(item.id)
)
:
null
))
The output is
1 3
,
but I want to get output after whole filter like
1,3
I want only the IDs where country is Austria as given below.
1,3
3
Answers
use
reduce
functionThis is How I Filter
One line answer: