Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return more than 1 value from JavaScript function?

How we can return more than one values from JavaScript function?

like image 696
Tom Rider Avatar asked Dec 16 '22 22:12

Tom Rider


2 Answers

Just return an object.

return { a:1, b:2 };
like image 124
josh3736 Avatar answered Jan 01 '23 02:01

josh3736


You could return an array:

function() {
    return [a, b];
}

Or an object:

function() {
    return {a: a, b: b};
}

Or assign values to an input:

function(ref) {
    ref.a = a;
    ref.b = b;
}
like image 29
Brian Nickel Avatar answered Jan 01 '23 01:01

Brian Nickel