ES6 面试题与答案
问题 11. What is the purpose of the 'map' function in ES6?
The 'map' function is used to transform each element of an array and create a new array with the results.
Example:
const numbers = [1, 2, 3]; const doubled = numbers.map(num => num * 2);
这有帮助吗?
添加评论
查看评论
问题 12. Explain the 'filter' function in ES6.
The 'filter' function is used to create a new array with elements that satisfy a given condition.
Example:
const numbers = [1, 2, 3, 4, 5]; const evens = numbers.filter(num => num % 2 === 0);
这有帮助吗?
添加评论
查看评论
问题 13. What is the purpose of the 'reduce' function in ES6?
The 'reduce' function is used to accumulate the elements of an array into a single value.
Example:
const numbers = [1, 2, 3, 4, 5]; const sum = numbers.reduce((acc, num) => acc + num, 0);
这有帮助吗?
添加评论
查看评论
问题 14. Explain the 'find' function in ES6.
The 'find' function is used to find the first element in an array that satisfies a given condition.
Example:
const numbers = [1, 2, 3, 4, 5]; const result = numbers.find(num => num > 2);
这有帮助吗?
添加评论
查看评论
问题 15. What are the rest parameters in ES6?
Rest parameters allow a function to accept an indefinite number of arguments as an array.
Example:
function sum(...numbers) { return numbers.reduce((acc, num) => acc + num, 0); }
这有帮助吗?
添加评论
查看评论
用户评价最有帮助的内容: