I am trying to return two values in JavaScript. Is that possible?
var newCodes = function() {
var dCodes = fg.codecsCodes.rs;
var dCodes2 = fg.codecsCodes2.rs;
return dCodes, dCodes2;
};
I am trying to return two values in JavaScript. Is that possible?
var newCodes = function() {
var dCodes = fg.codecsCodes.rs;
var dCodes2 = fg.codecsCodes2.rs;
return dCodes, dCodes2;
};
Few Days ago i had the similar requirement of getting multiple return values from a function that i created.
From many return values , i needed it to return only specific value for a given condition and then other return value corresponding to other condition.
Here is the Example of how i did that :
Function:
Getting Required return value from object returned by function :
The whole point of answering this question is to share this approach of getting Date in good format. Hope it helped you :)
In JS, we can easily return a tuple with an array or object, but do not forget! => JS is a
callback
oriented language, and there is a little secret here for "returning multiple values" that nobody has yet mentioned, try this:becomes
:)
bam! This is simply another way of solving your problem.
No, but you could return an array containing your values:
Then you can access them like so:
If you want to put "labels" on each of the returned values (easier to maintain), you can return an object:
And to access them: