javascript how to return multiple values 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
};
}