On Jun 28, 10:50 am, sjsean <SJSean95...@gm ail.comwrote:
All thanks in advance for reading my post. I am new to using js and
more accustomed to vbscript.
I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.
In doing some reading and research it seemed that js was more flexible
in this area. My questions:
1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)
I'm not sure what you mean by session variable, let's just talk about
javascript Array objects. As far as I know, you can mix javascript
and VBscript in the same page if they are in separate script elements,
you are using IE and you follow appropriate syntax so ID knows what is
VBscript and what is javascript. It is a very bad idea, I don't
recommend it at all - stick with one or the other, preferably
javascript if you want it to run in any browser other than IE.
2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?
It depends what you mean by delete. If you have an array of 12 items
with index 0 to 11, you can assign any value you like to any element,
so one version of delete might be to simply set an element's value to
'null' or ''.
If you use the Array splice method (which can be used to remove a
range of elements, not just one), the element is removed and your
array now has indexes 0 to 10 and a length of 11. You can also use
shift and pop to remove the first and last elements respectively.
3) any good articles about js, arrays, and multidimensiona l arrays
for a beginner?
For a brief introduction to javascript arrays (don't use for..in with
arrays, though it's good to know it's there):
<URL:
http://www.w3schools.com/js/js_obj_array.asp >
Then search the archives here. The ECMAScript specification isn't too
bad for arrays either, have a read and a bit of a play.
Some extras - initialise arrays using an initializer rather than a
constructor:
var arrayA = [];
var arrayB = ['foo', 'bar', 0, function(){...}];
The length property is automatically set as the largest used index
plus 1.
Sparse arrays are possible:
arrayA[10] = 'ipsum';
arrayA[100] = 'lorem';
alert(arrayA.le ngth); // shows 101
--
Rob