Thread: JavaScript Tutorial 1 - Arrays

Results 1 to 3 of 3
  1. #1 JavaScript Tutorial 1 - Arrays 
    Banned


    Join Date
    Aug 2010
    Posts
    3,267
    Thanks given
    598
    Thanks received
    1,086
    Rep Power
    0
    Hi, I will be showing you how to handle two types of arrays in Javascript, that will bring the same results.
    Way #1:

    Code:
    <script type="text/javascript">
    
    var things=new Array("lasers","swords","apples"); 
    alert(things[2]);
    <script>
    Now, that would bring the user a popup box saying "apples." Most would think it would bring up swords, because it is the second thing in the array. However, the computer does not read it like humans to. It reads like 0,1,2,3, etc. So, lasers would be 0, and so on.

    Way #2.
    Code:
    <script type="text/javascript">
    
    var things=new Array(); 
    
    things[0]="lasers"
    things[1]="swords"
    things[2]="apples"
    
    alert(things[2]);
    
    things[3]="grapes"
    alert(things[3]);
    
    <script>
    This is the way I prefer doing it, because it is a lot more clear on which variable is which. It's a personal preference thing though, really.
    Also; the only reason I added the alert in this tutorial without introducing it, is because I wanted to give the array a simple function. all the alert does is bring a pop-up to the screen.

    Elements-
    Code:
    <script type="text/javascript">
    
    var things=new Array(); 
    
    things[0]="lasers"
    things[1]="swords"
    things[2]="apples"
    
    alert(things[2]);
    
    things[3]="grapes"
    alert(things[3]);
    
    <script>
    As you can see, I have added something new to our array that is not under it. It appears after our first alert; but javascript reads from top to bottom. So, if you were to do this it would first alert apples, then after you click okay it will alert grapes. This is important to remeber that you do not have to add things right under the array, just keep the naming the same, It can also be useful while scripting.

    Inb4 everyone calls me an idiot: I JUST started learning javascript today lol
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member
    minutes's Avatar
    Join Date
    Apr 2008
    Posts
    1,918
    Thanks given
    2
    Thanks received
    18
    Rep Power
    465
    this is good for new on javascript, Im not good also on javascript but I knew this allrdy waiting for more parts


    good work!
    [Only registered and activated users can see links. ]
    click banner to join gtracer!
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Banned
    Join Date
    Dec 2011
    Age
    24
    Posts
    231
    Thanks given
    14
    Thanks received
    49
    Rep Power
    0
    Not To Bad.

    Good Job Legit.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JavaScript OOP Tutorial for Dummies
    By JavaScriptBank in forum Website Development
    Replies: 0
    Last Post: 10-21-2010, 06:27 AM
  2. JavaScript 5 in 1 Tutorial
    By T in forum Website Development
    Replies: 4
    Last Post: 05-01-2009, 07:42 PM
  3. JavaScript Beginners Tutorial
    By T in forum Website Development
    Replies: 6
    Last Post: 06-08-2008, 08:01 PM
  4. JavaScript 5 in 1 Tutorial!
    By T in forum Tutorials
    Replies: 3
    Last Post: 04-20-2008, 11:13 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •