Thursday, October 16, 2025
HomeLanguagesJavascriptJavaScript Return multiple values from function

JavaScript Return multiple values from function

In this article, we will see how to return multiple values from a function. In order to return multiple values from a function, we can not directly return them. But we can return them in form of an Array and Object. 

Example 1: This example returns the array [“GFG_1”, “GFG_2”] containing multiple values. 

Javascript




function set() {
    return ["GFG_1", "GFG_2"];
}
 
let [x,y] = set();
 
console.log(x);
console.log(y);


Output

GFG_1
GFG_2

Example 2: This example returns the object return {Prop_1: “Value_1”, Prop_2: “Value_2” }; containing multiple values. 

Javascript




function set() {
 
    return {
        Prop_1: "Value_1",
        Prop_2: "Value_2"
    };
}
 
console.log(set);
 
function returnVal() {
    let val = set();
    console.log("Prop_1 = " + val['Prop_1']
        + "Prop_2 = " + val['Prop_2']);
}
returnVal()


Output

[Function: set]
Prop_1 = Value_1Prop_2 = Value_2
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11953 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS