map
Given an array of numbers, return a new array where each number is squared.
const numbers = [2, 3, 4, 5];
Convert an array of strings to uppercase.
const words = ["hello", "world", "javascript"];
Given an array of objects with price
and quantity
, return an array with total prices (price * quantity
).
const items = [
{ price: 10, quantity: 2 },
{ price: 5, quantity: 5 },
{ price: 8, quantity: 3 }
];
filter
Given an array of numbers, return an array with only even numbers.
const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
Filter out strings with a length of less than 5 characters.
const words = ["apple", "bat", "banana", "cat", "grape"];
Given an array of objects representing students, return only the students who passed (marks >= 40
).
const students = [
{ name: "John", marks: 35 },
{ name: "Alice", marks: 50 },
{ name: "Bob", marks: 40 },
{ name: "Emma", marks: 30 }
];
forEach
Given an array of numbers, print each number multiplied by 2.
const numbers = [1, 2, 3, 4, 5];
Print each word in an array along with its length.
const words = ["JavaScript", "React", "Node", "MongoDB"];
Given an array of products, print the product name and price in the format: "Product: Laptop, Price: 50000"
.
const products = [
{ name: "Laptop", price: 50000 },
{ name: "Phone", price: 30000 },
{ name: "Tablet", price: 20000 }
];