How to return multiple value from Javascript ?


Hi

If you are working with java-script then you might be get scenario to return multiple value from function. Then we can return the multiple value like this code snippet as given below.

 


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultipleValueReturn.aspx.cs" Inherits="JavaScriptTest.MultipleValueReturn" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function test() {
            var no1 = 10;
            var no2 = 20;
            return {
                no1: no1,
                no2: no2
            };
        }

        function showAlertMsg() {
            var no3 = test().no1;
            alert(no3);
            var no4 = test().no2;
            alert(no4);
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="showAlertMsg();" />
    </div>
    </form>
</body>
</html>




Advertisements