0

I am trying to pass a string variable and two arrays to a global function. Something like this:

function send_times_to_device(stop_name, times, headsigns) {
  // function code here
}

Later in code:

...
var stop_name = "temp";
var times = new Array(json.length);
var headsigns = new Array(json.length);
...
if(times.length < 6){
  send_times_to_device(stop_name, times, headsigns);
}
...

How would I do this correctly in Javascript?

Thanks in advance!

EDIT: You guys were right, there was an error elsewhere in my code, this works!

4
  • 1
    Is there an error here? Commented Oct 23, 2015 at 17:59
  • 1
    I don't see a problem Commented Oct 23, 2015 at 17:59
  • that seems technically correct Commented Oct 23, 2015 at 18:00
  • Did you meant "Using an array as arguments to call a function with multiple parameters"? Commented Oct 23, 2015 at 18:02

1 Answer 1

1

new Array(n), creates an array with n undefined entries in it.

If you want to create an array with an integer value as the first entry use :

function send_times_to_device(stop_name, times, headsigns) {
  // function code here
    console.log(stop_name);
    console.log(times);
    console.log(headsigns);
}

var stop_name = "temp";
var times = [json.length];
var headsigns = [json.length];

send_times_to_device(stop_name, times, headsigns);
Sign up to request clarification or add additional context in comments.

Comments

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.