Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Array
- const numbers = [1, 2, 3, 4, 5];
- const even = numbers.filter((num, index, array) => num % 2 === 0);
- console.log(even); // [2, 4]
- // Object
- const users = [
- { id: 1, name: "Alice", active: true },
- { id: 2, name: "Bob", active: false },
- { id: 3, name: "Charlie", active: true }
- ];
- const activeUsers = users.filter(user => user.active);
- console.log(activeUsers);
- // [
- // { id: 1, name: "Alice", active: true },
- // { id: 3, name: "Charlie", active: true }
- // ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement