js return more than one value code example

Example 1: 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

Example 2: return multiple values in javascript

function getNames() {
    // get names from the database or API
    let firstName = 'John',
        lastName = 'Doe';

    // return values
    return {
        firstName,
        lastName
    };
}