LearnFast.Ninja

JavaScript array with two dimensions

How to create JavaScript array two dimensional declaration and how to retrieve the values.

Main idea:
var MyArray = [["a", 1], ["b", 2]];

Working example code:

<!DOCTYPE html>

<html>

<head>

    <title>Untitled Page</title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

    <script type="text/javascript">

        var MyArray = [["a", 1], ["b", 2]];

        document.writeln(MyArray[0][0]);

        document.writeln(MyArray[0][1]);

        document.writeln(MyArray[1][0]);

        document.writeln(MyArray[1][1]);

    </script>

</head>

<body>

</body>

</html>


Result:


Tags

javascript

array two-dimensions