I have an array of objects,
From which I want to conditionally create another array of objects.
Eg. -
var devs = [
{
name: 'A',
age: 26,
tech: ['JavaScript','React'],
addr:{
country:'India',
city:'Pune'
}
},
{
name: 'B',
age: 25,
tech: ['Node','AngularJs'],
addr:{
country:'USA',
city:'NY'
}
},
{
name: 'C',
age: 27,
tech: ['React','AWS'],
addr:{
country:'UK',
city:'London'
}
}
]
I want an Array of objects who have 'React' in their 'tech' field array,
And only want to display their Name and Tech,
The following is the expected output -
[
{
name: 'A',
tech: ['JavaScript','React']
},
{
name: 'C',
tech: ['Java','React'],
}
]
I know for conditional purpose filter method can be used,
But how do I leave out the unnecessary fields from the array of objects?
Can map method be used here? If so how do I implement it?
Following is my half cooked code -
var filteredDevs = devs.filter(temp => temp.tech.includes('React'));