Answers for "javascript return multiple values from a function"

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);
Posted by: Guest on May-26-2021
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 "javascript return multiple values from a function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language