Run

map, filter and reduce in JavaScript

Transform, filter and total an array of objects. Press Run to try it, then change the code and run it again.

main.js

const orders = [
  { item: "Momo", price: 120, veg: true },
  { item: "Thukpa", price: 150, veg: false },
  { item: "Tea", price: 40, veg: true },
];

const veg = orders.filter((o) => o.veg).map((o) => o.item);
const total = orders.reduce((sum, o) => sum + o.price, 0);

console.log("Veg items:", veg);
console.log("Total: ₹" + total);
console.table(orders);
Output

Press Run to see the output.

More JavaScript examples

Open the full JavaScript online compiler →