MCQs on Array Methods
1. What is the output? [1, 2, 3].forEach(num => num * 2); Options: ✅ Answer: B) undefined Explanation: 2. What is the output? let result = [1, 2, 3].map(num => { if (num > 1) return num * 2; }); console.log(result); Options: ✅ Answer: B) [undefined, 4, 6] Explanation: 3. What is the output? let arr = [1, 2, 3]; let result = arr.filter(num => num > 5); console.log(result); Options: ✅ Answer: B) [] Explanation: 4. What is the output? let result = [1, 2, 3].reduce((acc, val) => acc + val); console.log(result); Options: ✅ Answer: A) 6 Explanation: 5. What is the output? let arr = [1, 2, 3]; let result = arr.some(num => num > 2); console.log(result); Options: ✅ Answer: A) true One element (3) satisfies condition 6. What is the output? let arr = [2, 4, 6]; let result = arr.every(num => num % 2 === 0); console.log(result); Options: ✅ Answer: A) true All elements satisfy condition 7. What is the output? let arr = [1, 2, 3]; arr.map(num => num * 2); console.log(arr); Options: ✅ Answer: B) [1, 2, 3] map() does NOT modify original array 8. What is the output? let arr = [1, 2, 3]; arr.forEach(num => num * 2); console.log(arr); Options: ✅ Answer: B) [1, 2, 3] 9. What is the output? let arr = [1, [2, 3]]; console.log(arr.flat()); Options: ✅ Answer: A) [1, 2, 3] 10. What is the output? let arr = [1, 2, 3]; let result = arr.reduce((acc, val) => acc + val, 5); console.log(result); Options: ✅ Answer: B) 11 5 + 1 + 2 + 3 = 11 11. What is the output? console.log([..."hello"]); Options: ✅ Answer: B 12. What is the output? let arr = [10, 20, 30]; console.log(arr.at(-1)); Options: ✅ Answer: B) 30
