I am trying to filter one array of objects that looks like this
const ELEMENT_DATA: PeriodicElement[] = [
{ position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H' },
{ position: 2, name: 'Helium', weight: 4.0026, symbol: 'He' },
{ position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li' },
{ position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be' },
{ position: 5, name: 'Boron', weight: 10.811, symbol: 'B' }
];
And an array that looks like this
const values = [1,5];
What I need is to filter ELEMENT_DATA to NEW_VALUES look like this
const NEW_VALUES: PeriodicElement[] = [
{ position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H' },
{ position: 5, name: 'Boron', weight: 10.811, symbol: 'B' }
];
I have tried with filter like this:
filterData(locationName: any) {
return ELEMENT_DATA.filter(object => {
return object.position === locationName;
});
}
but always I get an empty array.
1 === [1, 5]?!