gpt4 book ai didi

JavaScript 嵌套内部 for 循环不起作用

转载 作者:行者123 更新时间:2023-12-02 21:03:08 27 4
gpt4 key购买 nike

我想将 bobsFollower 数组和 tinasFollower 数组中的公共(public)字符串存储在 mutualFollowers 数组中。

const bobsFollowers = ['vinit','vidyesh','bipin','shobhana'];
const tinasFollowers = ['vinit','vidyesh','manish'];
const mutualFollowers = [];
for (let i = 0; i < bobsFollowers.length; i++){
for (let j = 0; j < tinasFollowers.lenght; j++){
if (bobsFollowers[i] === tinasFollowers[j]){
mutualFollowers.push(tinasFollowers[j]);
}
}
};
console.log(mutualFollowers);

未执行内部 for 循环

最佳答案

您在内循环中出现拼写错误:您将 length 错误地输入为 lenght!

const bobsFollowers = ['vinit','vidyesh','bipin','shobhana'];
const tinasFollowers = ['vinit','vidyesh','manish'];
const mutualFollowers = [];
for (let i = 0; i < bobsFollowers.length; i++){
for (let j = 0; j < tinasFollowers.length; j++){
if (bobsFollowers[i] === tinasFollowers[j]){
mutualFollowers.push(tinasFollowers[j]);
}
}
};
console.log(mutualFollowers);

关于JavaScript 嵌套内部 for 循环不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61288858/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com