問題文
A developer needs a new array holding the length of every name in names, without changing names. Which call satisfies both requirements?
選択肢
- names.forEach(function (n) { return n.length; }), which collects every returned value into a new array once the iteration has finished.
- names.map(function (n) { return n.length; }), which returns a new array of the same length and leaves names untouched.
- names.reduce(function (n) { return n.length; }), which replaces each element with its length in place.
- names.filter(function (n) { return n.length; }), which returns the length of every name.