Java Script: Nested Return Statement, return inside Return
<p>In one of my previous question <a href="https://stackoverflow.com/questions/36148888/js-multiple-return-in-ternary-operator">js: Multiple return in Ternary Operator</a> I asked about returning multiple parameter with ternary-operator. But now the parameter <strong>IsActveUser boolean(true|false)</strong> flag have been modified to <strong>integer(0|1|2|3) flag</strong>, </p>

<p>Previously it has only two states,</p>

<pre><code>True - Valid User
False - InValid User
</code></pre>

<p>now it has four states, </p>

<pre><code>0 - InValid User
1 - Valid User
2 - Future User
3 - Expired User
</code></pre>

<p>So previously, I have coded like, </p>

<pre><code>var data = userInfo.map(function (element) {
    return {
        'LastName': Capitalizefirstletter(element[1]),
        'FirstName': Capitalizefirstletter(element[2]),
        'UserName': element[3],
        'IsActiveUser': ~element[9].search("Valid") ? "True": "False" // really a string?
    };
)}
</code></pre>

<p>Now I have to check like this, for four status flag</p>

<pre><code>var data = userInfo.map(function (item) {
    if (item[9].search("title = \"Expired\"")) {
        return {
            'LastName': Capitalizefirstletter(item[1]),
            'FirstName': Capitalizefirstletter(item[2]),
            'UserName': item[3],
            'UserStatusFlag': 3 // flag should be 3 in this case
        };
    }
    else if (item[9].search("title = \"Valid\"")) {
        return {
            'LastName': Capitalizefirstletter(item[1]),
            'FirstName': Capitalizefirstletter(item[2]),
            'UserName': item[3],
            'UserStatusFlag': 1 // flag should be 1 in this case
        };
    }
    else if (item[9].search("title = \"Invalid\"")) {
        return {
            'LastName': Capitalizefirstletter(item[1]),
            'FirstName': Capitalizefirstletter(item[2]),
            'UserName': item[3],
            'UserStatusFlag': 0 // flag should be 0 in this case
        };
    }
    else if (item[9].search("title = \"Future\"")) {
        return {
            'LastName': Capitalizefirstletter(item[1]),
            'FirstName': Capitalizefirstletter(item[2]),
            'UserName': item[3],
            'UserStatusFlag': 2 // flag should be 2 in this case
        };
    }
});
</code></pre>

<p>but this is not working as expected in Knockout JS. </p>

<p>Shall I use anything like this, else-if checking inside return satement</p>

<pre><code>var data = userInfo.map(function (element) {
    return {
        'LastName': Capitalizefirstletter(element[1]),
        'FirstName': Capitalizefirstletter(element[2]),
        'UserName': element[3],
        'UserStatusFlag': if(~element[9].search("Valid")) {1}
                                    else if (~element[9].search("InValid")) {0}
                                    else if (~element[9].search("Future")) {2}
                                    else if (~element[9].search("Expired")) {3}
    };
})
</code></pre>

<p>Any suggestion would be helpful.</p>