Playwright + TS · Lesson 3 of 36
Module 3: Arrays & Objects
Your task
Given an array of test cases:
status === "failed".name strings.Write it in the editor, then press Check answer (Ctrl + Enter).
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); // falseJSON.stringify(data): Converts JavaScript objects into a JSON string for API payloads.JSON.parse(jsonString): Converts raw JSON strings back into JavaScript objects.In test automation, you frequently work with lists of web elements, test data tables, and API responses. In this lesson, we will master arrays and objects, along with powerful methods like map, filter, find, and reduce. We will also learn how to parse and stringify JSON data. Let's get hands-on!
Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
find() stops at the first matching element and returns a single item (or undefined). filter() iterates the entire array and returns an array of all matching items.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___