Idea:
- flatten the nested array into an simple array
- filter the result from the simple array
Method I: Quick and concise
const result = [].concat(...input).filter(item => item.startDate === formatCalendarDates);
Method II: Using a library (e.g. Ramda) to flatten it
R.flatten(data).filter(item => item.key === 'a');
See the live result here.
Method III: do it manually:
const data = [
[
{ key: 'a', value: 1 },
{ key: 'b', value: 2 },
{ key: 'c', value: 3 },
{ key: 'a', value: 4 },
{ key: 'b', value: 5 },
{ key: 'a', value: 6 }
], [
{ key: 'b', value: 7 },
{ key: 'b', value: 8 },
{ key: 'a', value: 9 }
], [
{ key: 'c', value: 10 },
{ key: 'b', value: 11 },
{ key: 'b', value: 12 }
]
];
const flat = data => {
let output = [];
data.map(arr => output = [... arr, ... output]) ;
return output;
}
const result = flat(data).filter(item => item.key === 'a');
console.log(result);