xxxxxxxxxx
function twoValues() {
return [0, 1];
}
let [first, second] = twoValues();
xxxxxxxxxx
//function that returns multiple values
function getTopTwoColors() {
return ["blue", "pink"];
}
var topTwoColors=getTopTwoColors();
var firstValue=topTwoColors[0]; //get first return value
var secondValue=topTwoColors[1]; //get second return value
xxxxxxxxxx
function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';
// return as an array
return [firstName, lastName];
}
Code language: JavaScript (javascript)