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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 232
    Comment on it


    variables are good and sufficient to hold the single values, But what if we want to store multiple values in a single variable in that case you have to use arrays or objects


    Values in arrays are saved index base. Remember that arrays in JavaScript are zero based, arrays are declared using the array literal notation [].


    We can categories JavaScript array on base of there style of saving values.


    <html>
    
        <script type="text/javascript">
            /* Declare array*/      
            var myself = [];
    
            /* initialize the array */
            myself[0] = 'book1';
            myself[1] = 'book2';
    
            /*access the value of a specific element*/
    
            alert(myself[1]); 
            /*OR*/
            console.log(myself[1])
        </script>   
    
    
    </html>
    

    Arrays can contain various types of data for example

    var arrayexample = ["naveen",100,"true","DUCK"];
    


    Multidimensional array, a combination of arrays inside an array, and is considered as more complex type pf array. for example


    var example1 = array[100,200,300,400,500];
    var example2 = array['hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred'];
    var multidimensionalarray = [example1, example2];
    


    Retrieving value of multidimensional array


    alert(multidimensionalarray[1][2]);
    


    we can also declare JavaScript array like below

    var myshelf = new Array()
    


    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: