I get the following data from an API:
[
{ names: { name: 'Pete', name;'Claus' } },
{ names: { name: 'Paul', name;'Claus' } },
{ ... }
]
How can I get an array containing only those objects that have the name Claus in them with reduce,filter, map and such methods?
This does it - but not in a functional style though:
var newMap = []
var map = this.array
for(var i = 0; i < map.length; i++) {
for(var j = 0; j < map.length; j++) {
if(map[i] && map[i].involvements[j])
if(map[i].involvements[j].full_name === 'Claus') {
newMap.push(map[i])
}
}
}
this.array = newMap
Some bits not very much though:
search(){
let map = this.submissions
.map( (x,i) => x.involvements.filter(x => x.full_name === 'Claus'))
.filter( x => x.length != 0 )
console.log(map)
}