I have an issue which I do not how to resolve.
I want to map data with .map((x) => x.data) with one-liner if statement inside, but without any else statement. I would like to achieve more or else 'pass' just as in Python.
In example:
What I want:
let mappedData = data.map((x) => x.data === filters.data ? [x.value, x.name, x.category]: pass);
This should return mappedData with data that only fill the condition.
When I use sth like this
let mappedData = data.map((x) => x.data === filters.data ? [x.value, x.name, x.category]: {});
It returns array of size data and with empty dicts if condition is not filled.
I tried as well sth like this:
let mappedData = data.map((x) => x.data === filters.data && [x.value, x.name, x.category]);
But that gives me false at each index that does not fill the condition.
I really would like to do one-liner if possible.
Thanks guys
Not exactly sure what you want, but will this help?
let data = [{name: "Peter", age:29}, {name: "Rina", age: 36}, {name: "Joseph", age: 37}];
let filters = {name: "Rina", age: 36};
let res=[];
data.map((item) => {(item.name === filters.name)? res.push(item):null});
console.log(res);
let mappedData = data.map((x) => x.data === filters.data ? [x.value, x.name, x.category]: pass);