return more than 1 value from function js code example

Example 1: return more than 1 value from function js

//Function that returns multiple values - Using destructuring

function foobar(foo, bar) {
  return [foo, bar];
}

const [one, two] = foobar(1, 2);

Example 2: javascript return multiple values from a function

//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

Tags:

Misc Example