我有两个列表需要一起迭代。让我展示如何:
listA=[1,2,3,4]
listB=["A","B","C"]
Run Code Online (Sandbox Code Playgroud)
从这些列表中,我想要这个列表
ListC=("1A","2B","3C","4A")
Run Code Online (Sandbox Code Playgroud)
甚至制作一个更长的列表,我可以在其中循环相同的迭代
ListC=("1A","2B","3C","4A","1B","2C","3A","4C".... and so on)
Run Code Online (Sandbox Code Playgroud)
我在网上找不到任何可以回答这个问题的教程 谢谢。
我正在学习 JavaScript 课程。我正在读“对象和类”一章,我不知道如何解决作业中的一些作业。第一个练习是这样的
function createCat(name,age){
//Create a new object with the property "name" and the value defined by the argument "name".
//Add a new property to the object with the name "age" and use the value defined by the argument"age"
//Add a methos (function) called meow that returns the string "Meow"!
}
Run Code Online (Sandbox Code Playgroud)
这就是我正在尝试的
function createCat(name,age){
var Cat={};
Cat.Name=name;
Cat.Age=age;
Cat.meow=function(){return "Meow!"};
return Cat;
}
Run Code Online (Sandbox Code Playgroud)
我正在测试将脚本加载到 index.html 文件中的功能,在浏览器中打开该文件,然后在 Web 控制台中测试该功能。我运行该函数没有问题。然后,我测试 Cat 对象是否是通过在控制台中写入 Cat.Name 返回的,这会导致错误。当我在下面的一行代码中调用该函数,然后尝试访问该对象的属性时,也会发生同样的事情。错误显示为“ReferenceError:Cat 未定义”。我究竟做错了什么?谢谢!