I am trying to run a function in my JavaScript code. I'm trying to create two arrays, one with arabic words and one with the translated words in english, where corresponding words in each array have the same index. The purpose of the function is so that I can add an arabic word and its translation simultaneously.
我试图在我的JavaScript代码中运行一个函数。我正在尝试创建两个数组,一个使用阿拉伯语单词,另一个使用英语翻译单词,每个数组中的相应单词具有相同的索引。该功能的目的是让我可以同时添加阿拉伯语单词及其翻译。
The function doesn't run when I call it, and I have determined that the fact I am passing parameters in the function is what's causing it to not run. Why does this happen and how can I get the function to run? The script is in the <body>
of the HTML.
当我调用它时,该函数不会运行,并且我已经确定我在函数中传递参数的事实是导致它无法运行的原因。为什么会发生这种情况?如何才能运行该功能?该脚本位于HTML的中。
This is my code:
这是我的代码:
var arabic = [];
var english = [];
function addToArrays(arabic, english) {
arabic.push(arabic);
english.push(english);
}
addToArrays("string1", "string2");
1 个解决方案
#1
5
Your parameter names are override your arrays. So what you need to do is rename your parameters. Something like this should work.
您的参数名称将覆盖您的数组。所以你需要做的是重命名你的参数。这样的事情应该有效。
var arabic = [];
var english = [];
function addToArrays(a, e) {
arabic.push(a);
english.push(e);
}
addToArrays("string1", "string2");
#1
5
Your parameter names are override your arrays. So what you need to do is rename your parameters. Something like this should work.
您的参数名称将覆盖您的数组。所以你需要做的是重命名你的参数。这样的事情应该有效。
var arabic = [];
var english = [];
function addToArrays(a, e) {
arabic.push(a);
english.push(e);
}
addToArrays("string1", "string2");