How to pass single parameter in function and return multiple parameter in that function in js? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to pass single parameter in function and return multiple parameter in that function in js?

How return multiple parameter

30th Jun 2020, 3:35 AM
poo malai
poo malai - avatar
3 Answers
+ 5
as AJ Anant said: function myFunction(){ //Some logical code //Returning as an object return { value1: "some value", value2: 2 //as many as you need } //as an array return ["some value", someVar, 2, /*...*/]; } const value = myFunction ();
30th Jun 2020, 3:50 AM
CoffeeByte
CoffeeByte - avatar
+ 2
You can return multiple output parameters using deconstruction of function output object. function getName(fullname) { const names = fullname.split(" "); return { firstname: names[0], lastname: names[1] } } const { firstname, lastname } = getName("Bill Gate"); https://code.sololearn.com/W4rtV778ypMM/?ref=app
30th Jun 2020, 4:50 AM
Calviղ
Calviղ - avatar
+ 1
poo malai Return multiple values not multiple parameters. You can return multiple values as an array.
30th Jun 2020, 3:42 AM
A͢J
A͢J - avatar