# 与rest运算符和循环混淆

##### 问题描述投票：0回答：2

``````let arr1 = ["one", "two", "three"];
let arr2 = ["four", "five", "six"];
function debug_qty(arr) {
let post_arr_filter = arr.map(function(word) {
return `\${word.length}`;
});
return post_arr_filter;
};
``````

[我已经尝试过下面的方法，但是它只打印第一个数组，当我附加.length时，得到3，而不是3,3,5（各个字符串的长度）。

``````let arr1 = ["one", "two", "three"];
let arr2 = ["four", "five", "six"];

function check_length(...args) {
for (let arrs in args) {
return args[arrs].length;
};
};
``````

``````function calc_arr(...args) {
let result = args.map(function(nums) {
return nums.length;
});
return result;
}
``````

javascript
##### 2个回答
0

``````let arr1 = ["one", "two", "three"];
let arr2 = ["four", "five", "six"];

function calc_arr(...args) {
return args.map((arr) => {
return arr.map((word) => {
return word.length;
})
})
}

const res = calc_arr(arr1,arr2);
console.log(res);``````

1

`for...in`方法的问题在于，您将返回inside循环（还请注意，您实际上应该仅使用`for...in` for iterating object properties，而不是数组索引）。 `for...in`使您的函数退出，然后结束循环。

``.map()``

``.flatMap()``

``Array.from``