1

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.

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.

This is my code:

var arabic = [];
var english = [];    
function addToArrays(arabic, english) {
    arabic.push(arabic);
    english.push(english);
}
addToArrays("string1", "string2");
2
  • 3
    I've mapped every word in the english language to foo or bar and will attempt to answer your question... Foo foo bar foo bar bar foo foo. Bar bar bar, foo foo bar foo. Foo bar? Commented Jun 4, 2012 at 2:25
  • @mVChr - Hello world hello world world hello hello hello world world hello hello. World hello hello world world hello, world? Commented Jun 4, 2012 at 3:19

1 Answer 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");
Sign up to request clarification or add additional context in comments.

3 Comments

Of course! It makes so much sense now. arabic.push(arabic) is pushing the string onto itself - not onto the array. Thank you!
@user1434249 If somebody helped you on StackOverflow you should upvote them and accept their answer.
thanks dunsmoreb, I've done that. This is the first time I've used StackOverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.