Can you simplify these function calls by chaining them? Is there a way to combine forEach, push, array destructuring, and map?
let selectorsForLoader = ['a', 'b'];
let loadingElements = [];
selectorsForLoader.forEach(selector => {
loadingElements.push(...Array.from(document.querySelectorAll(selector)));
});
let loaders = loadingElements.map(loadingElement => {
loadingElement.doSomething();
});
Is it possible to achieve something like this with function chaining:
food.map(item => item.type)
.reduce((result, fruit) => {
result.push(fruit);
return [...new Set(result)];
}, []);