Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make function return more than one value

Tags:

javascript

This is my code:

var Evalcard =  function(number) {
    if (number == 1) {
        this.name = "Ace";
        this.value = 11;
    }
    else if (number == 11) {
        this.name = "Jack";
        this.value = 10;
    }
    else if (number == 12) {
        this.name = "Queen";
        this.value = 10;
    }
    else if (number == 13) {
        this.name = "King";
        this.value = 10;
    }

    return {this.name,this.value};

I'm pretty sure this return statement is not correct. How do you make a function return more than one value? Any help at all would be great.

like image 481
dopatraman Avatar asked Feb 27 '26 05:02

dopatraman


2 Answers

In this case, you probably want to return either an array or an object literal:

return { name: this.name, value: this.value };
// later: EvalCard(...).name; EvalCard(...).number;


return [ this.name, this.value ];
// later: EvalCard(...)[0]; EvalCard(...)[1];
like image 132
Nick Husher Avatar answered Mar 01 '26 19:03

Nick Husher


How about this:

return [this.name, this.value];
like image 30
helpermethod Avatar answered Mar 01 '26 19:03

helpermethod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!