const products = [
{ name: "Pro Laptop", price: 1200, inStock: true },
{ name: "USB Cable", price: 15, inStock: false },
{ name: "Wireless Mouse", price: 45, inStock: true },
];// 1. map(): transform each item into another shape
const productNames = products.map((p) => p.name);
// Result: ["Pro Laptop", "USB Cable", "Wireless Mouse"]
// 2. filter(): extract items matching a criteria
const availableProducts = products.filter((p) => p.inStock);
// 3. find(): return the first matching item or undefined
const cable = products.find((p) => p.name === "USB Cable");
// 4. some() & every(): check boolean conditions
const hasExpensiveItem = products.some((p) => p.price > 1000); // true
const allInStock = products.every((p) => p.inStock); // false
JSON.stringify(data): Converts JavaScript objects into a JSON string for API payloads.
- JSON.parse(jsonString): Converts raw JSON strings back into JavaScript objects.