return multiple values in javascript
//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
function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';
// return values
return {
firstName,
lastName
};
}function doubleEachElement(num1, num2) {
return [num1 * 2, num2 * 2];
}
const [a, b] = doubleEachElement(68, 100);var values = getValues();
var first = values[0];
var second = values[1];
Also in JavaScript:
- javascript loop through object properties
- javascript sendredirect
- get uislider
- how to smooth scroll in javascript
- price range slider bootstrap 4
- js C:\fakepath
- javascript print array
- w3 cookies js
- SFC in react
- reverse a string program in javascript
- stop a video jquery
- str_word_count php js
- add style javascript
- convert to float in javascript
- how to check if array
- change items per page pagination angularjs
- get child element by class javascript
- How to remove the first and the last character of a string
- remove character at index
- align left text in reactstrap
- sort array based on another array js
- Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'
- hide and show in angular 8
- socket io query