0
How to pass single parameter in function and return multiple parameter in that function in js?
How return multiple parameter
3 Respuestas
+ 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 ();
+ 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
+ 1
poo malai Return multiple values not multiple parameters. You can return multiple values as an array.