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;
};
Best way for this is
Then use
return 4
in ES6 you can use this code
You can use "Object"
Just return an object literal
Since ES6 you can do this
Return expression
{dCodes, dCodes2}
is property value shorthand and is equivalent to this{dCodes: dCodes, dCodes2: dCodes2}
.This assignment on last line is called object destructing assignment. It extracts property value of an object and assigns it to variable of same name. If you'd like to assign return values to variables of different name you could do it like this
let {dCodes: x, dCodes2: y} = newCodes()
All's correct.
return
logically processes from left to right and returns the last value.Ecmascript 6 includes "destructuring assignments" (as kangax mentioned) so in all browsers (not just Firefox) you'll be able to capture an array of values without having to make a named array or object for the sole purpose of capturing them.
You can try it out in Firefox already!