Enumerating the Contents of an Array - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

You enumerate the content of an array using a for loop.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script type="text/javascript">
            var myArray = [100, "java2s.com", true];
            for (var i = 0; i < myArray.length; i++) {
                document.writeln("Index " + i + ": " + myArray[i]);
            }/*from  w ww  .j  ava2 s  .  c  om*/
        </script>
    </body>
</html>

Related Tutorials