Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Arrays in JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 318
    Comment on it

    JavaScript Arrays : Array is a like a container which contains the same type of objects or elements. Arrays has fixed length. We can access the array elements using the index value.The index of the array starts from 0.


    Example of creating array in JavaScript : Here in following example I will show you how to create a array in JavaScript.

    CreateArray.html

    1. <!DOCTYPE html>
    2. <html>
    3. <body>
    4.  
    5. <p>To create an array and display it's constructor, Click the button.</p>
    6. <button onclick="createArray()">Create Array</button>
    7. <p id="container"></p>
    8.  
    9. <script>
    10. function createArray() {
    11. var students = ["Ashok", "Nitin Kumar", "Rajesh", "Sumit"];
    12. document.getElementById("container").innerHTML = students;
    13. }
    14. </script>
    15.  
    16. </body>
    17. </html>

    Output :

    1. Ashok,Nitin Kumar,Rajesh,Sumit

    Array has a property called constructor, this is used to know the constructor method of the object.


    Example of the Array constructor property :

    1. <!DOCTYPE html>
    2. <html>
    3. <body>
    4.  
    5. <p>To create an array and display it's constructor, Click the button.</p>
    6. <button onclick="createArray()">Create Array</button>
    7. <p id="container"></p>
    8.  
    9. <script>
    10. function createArray() {
    11. var students = ["Ashok", "Nitin Kumar", "Rajesh", "Sumit"];
    12. document.getElementById("container").innerHTML = students.constructor;
    13. }
    14. </script>
    15.  
    16. </body>
    17. </html>

    Output :

    1. function Array() { [native code] }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: