how to return 2 values in javascript code example
Example 1: can you return 2 values in javascript object
function friends(){
var names = {
closeCircle: ['bebo','eli','matthew'],
outerCircle:['vierie','nate','james','george'],
};
return [names.closeCircle[0], names.closeCircle[2]]
}
Example 2: javascript return multiple values from a function
function getTopTwoColors() {
return ["blue", "pink"];
}
var topTwoColors=getTopTwoColors();
var firstValue=topTwoColors[0];
var secondValue=topTwoColors[1];
Example 3: return multiple values in javascript
function getNames() {
let firstName = 'John',
lastName = 'Doe';
return {
firstName,
lastName
};
}
Example 4: javascript function multiple return
function doubleEachElement(num1, num2) {
return [num1 * 2, num2 * 2];
}
const [a, b] = doubleEachElement(68, 100);