Playwright + JS · Lesson 3 of 35
Module 3: Arrays & Objects
Try it yourself
Implement filterActiveUsernames:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
const testUsers = [
{ id: 1, name: "Admin", role: "ADMIN", active: true },
{ id: 2, name: "Tester", role: "QA", active: true },
{ id: 3, name: "Guest", role: "VIEWER", active: false },
];
// Extract usernames with map:
const usernames = testUsers.map(u => u.name);
// Filter active users:
const activeUsers = testUsers.filter(u => u.active);
// Check if any admin exists:
const hasAdmin = testUsers.some(u => u.role === "ADMIN");
// JSON serialization:
const jsonString = JSON.stringify(testUsers);
const parsedData = JSON.parse(jsonString);In automation, you will constantly parse test data files, filter table records, and validate API JSON responses. In this lesson, we will master arrays, objects, higher-order methods like map and filter, and JSON serialization. Let's get hands-on!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
find() returns the single first matching item (or undefined). filter() returns a new array with all matching items.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.