473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Understanding Array Object's? baskets[baskets.length]=o;

A Simple program, all I'm trying to do is input item and quantity into a text box and then display them, I have written the following code, however I'm unclear what the following line does: baskets[baskets.length]=o;

Can someone explain to me what this line actually does? Thank you


See below for my coding:

Expand|Select|Wrap|Line Numbers
  1.  
  2. var baskets=[];
  3.  
  4. function doAction() {
  5.  
  6.    var item=document.getElementById("item").value;
  7.    var quantity=document.getElementById("quantity").value;
  8.  
  9.     var o=new basket(item,quantity);
  10.     baskets[baskets.length]=o;  
  11.     ShowItem_All();    
  12. }
  13.  
  14. function basket(item,quantity) {
  15.  
  16.     this.item=item;
  17.     this.quantity=quantity;
  18. }
Aug 20 '07 #1
4 1385
pbmods
5,821 Expert 4TB
Heya, Divina.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 20 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

i comment the code:


Expand|Select|Wrap|Line Numbers
  1.  
  2. // declare an array for storing your items
  3. var baskets = [];
  4.  
  5. function doAction() {
  6.     // retrieve the inputvalues
  7.     var item = document.getElementById("item").value;
  8.     var quantity = document.getElementById("quantity").value;
  9.  
  10.     // create an instance of the below defined obj basket
  11.     // it calls the constructor with two params that are 
  12.     // instantly assigned as member variables to the obj-
  13.     // instance
  14.     var o = new basket(item,quantity);
  15.  
  16.     // add the instance to the array at the last index
  17.     // it is the same as baskets.push(o);
  18.     baskets[baskets.length] = o;
  19.  
  20.     // some function call
  21.     ShowItem_All();    
  22. }
  23.  
  24. // this is the constructor (quasi-class) for a basket-obj
  25. // it receives 2 params that are stored in the obj-instance
  26. function basket(item, quantity) {
  27.     this.item = item;
  28.     this.quantity = quantity;
  29. }
  30.  
kind regards
Aug 20 '07 #3
Thank you Gits, that was a very clear explaination.

Ta XXX
Aug 21 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

no problem ... glad to be able to help you ... and whenever you have more questions then post in the forum again

kind regards
Aug 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: User | last post by:
Hi, This is very basic, It may be a repost, if so I'm sorry. The problem is that this declaration : Private strMyArray(100) As String will create an array of string with a length of 101,...
4
by: F Da Costa | last post by:
Hi, Small question re the use of an Array. I'v got an array with x rowObjects in it. When i get it the type of the container is Array and i can get a hold of the objects just fine. owever,...
7
by: Jamil Anwar Zaman | last post by:
If I dynamically allocate memory to a pointer, then is it possible to see afterwards what is the memory size the pointer is looking at. e.g int SIZE = 10; int *a = malloc(SIZE*sizeof(int));...
1
by: Rene | last post by:
I have an array that may or may not contain data during the course of its life. When I first instantiate my class level array reference I set the array to null: int xyz = null; But I am thinking...
1
by: Samuel R. Neff | last post by:
Are there any differences between using Array.Length and Array.GetUpperBound(0) on a one-dimensional array? We have a team of developers and most people use Array.Length but one developer uses...
3
by: Madhu | last post by:
I would like to know how the following will be handled in the .net framework: Pl. don't pay attention to the syntax int a int b a=2 a=2 a=2
18
by: Frederick Gotham | last post by:
Many people use a method quite akin to the following to determine an array's length: #define NUMELEM(arr) (sizeof (arr) / sizeof *(arr)) I recall reading an article written by Alf P. Steinbach...
2
by: Garg | last post by:
if we assign array.length = 0 then what does it mean? Are we setting the length of the array equal to 0 or are we selecting the first element of the array? Please help me on this..
3
by: 2n2is5 | last post by:
I've been experimenting with arrays, and I have just found the simple way to find the length of an array. I attempted to make this a function with the specific array as the only argument. It didn't...
3
by: Steve | last post by:
I am having problems with this piece of script. Usually the script works and the alert gives an array length of 9. But every so often the array length is 8 and naturally the output is then wrong....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.