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);
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);
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
return multiple values in javascript
function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';
// return values
return {
firstName,
lastName
};
}
javascript function multiple return
function doubleEachElement(num1, num2) {
return [num1 * 2, num2 * 2];
}
const [a, b] = doubleEachElement(68, 100);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us