Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  125] [ 3]  / answers: 1 / hits: 15843  / 7 Years ago, tue, october 24, 2017, 12:00:00

How can i return multiple values from the function in javascript. And how to use that.??


More From » angular

 Answers
70

You can't do that.



But, you can return an array or an object which contains your values.





function doSomething(a,b){
return [a,b];
//return {a,b};
}
console.log(doSomething(1,2));





If you want to return many values you can use destructing operator in order to find out all the values.





function doSomething(a,b,c,d,e,f){
return {a,b,c,d,e,f};
}
let {a,b,c,d,e,f}=doSomething(1,2,3,4,5,6);
console.log(a,b,c,d,e,f);




[#56140] Saturday, October 21, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aiyannam

Total Points: 642
Total Questions: 96
Total Answers: 102

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;