Medium
What is the purpose of Array.prototype.flatMap in JavaScript, and how does it differ from combining map and flat?
1const nestedArray = [2 { category: 'fruits', items: ['apple', 'banana'] },3 { category: 'vegetables', items: ['carrot', 'spinach'] },4];56const flatMapped = nestedArray.flatMap((entry) => entry.items);78console.log(flatMapped);