Answers for "return multiple values in javascript"

13

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
Posted by: Guest on July-31-2019
5

return multiple values in javascript

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

    // return values
    return {
        firstName,
        lastName
    };
}
Posted by: Guest on August-10-2020
0

javascript function multiple return

function doubleEachElement(num1, num2) {
  return [num1 * 2, num2 * 2];
}
const [a, b] = doubleEachElement(68, 100);
Posted by: Guest on December-08-2020

Code answers related to "return multiple values in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language