Click to See Complete Forum and Search --> : another array question
pelegk1
06-24-2003, 01:16 AM
i wanted to make a 2d array :
<script language="javascript">
var SubCatList=new Array(2);
function x(){
for(i=0;i<1-;++i){
SubCatList[i][0]=i;
SubCatList[i][0]=i+1;
}
}
but i get about the lines in the for loop that "SubCatList" isn't an object :(
why is that?
pelegk1
06-24-2003, 01:31 AM
<script language="javascript">
var SubCatList=new Array(2);
function x(){
for(i=0;i<1-;++i){
SubCatList=new Array(2);
SubCatList[i][0]=i;
SubCatList[i][0]=i+1;
}
}
pelegk1
06-24-2003, 08:09 AM
i just type it forgetting the [i]
so what is more correct ++i or i++ in javascript?
maybe its the same as c++
jeffmott
06-24-2003, 09:42 PM
It does matter in JavaScript, actually. And, pelegk1, it does function the same as in C/C++.
pelegk1
06-24-2003, 11:42 PM
and are u a real perl hacker?what odes it mean?
and how u so shore that in javascript it acts the same as in c++ (not like c beacuse c dosen't have operator overloading)?
jeffmott
06-25-2003, 06:49 AM
how u so shore that in javascript it acts the same as in c++Both reading and simple testing.Core JavaScript Reference 1.5
This operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.not like c beacuse c dosen't have operator overloadingC has the auto increment/decrement operators as well. Though it is not considered overloading. It is still the same operator whether it is used prefix or postfix. C must also support operator overloading as well because it has a binary + and -, and a unary + and -. The former performs addition/subtraction and the latter performs sign change (negation).
pelegk1
06-26-2003, 01:30 AM
x++ and ++x is the same!?!?
now way man!
x++ means first do the code and only after that
increase!
++x means first increase and only after that do the rest of the code for example
arr1[x++]=i
isn't the same as
arr1[++x]=i
jeffmott
06-26-2003, 06:53 AM
I never said they returned the same value. In fact I said the opposite. But there is still only one operator. The distinction of what value to be returned as its result is determined by the context in which it was used (prefix/postfix). For example,hypothetical code
x.addOne('return before increment');
x.addOne('return after increment');Would you consider the two hypothetical methods above as different methods because they won't return the same value?
SlankenOgen
06-26-2003, 06:54 AM
When there are 2 operands it matters whether you pre or post increment (++i and i++ respectively)
eg.
var x = 1;
var y = 0;
y = x++;
this makes y = 1 and x = 2;
x is assigned to y then x is incremented.
Now try-
var x = 1;
var y = 0;
y = ++x;
This is pre increment.
y is now 2 and x is 2.
x is incremented first then the second operator "=" is executed.
So post assigns first then increments. Pre increments first then assigns.
~mgb
pelegk1
06-29-2003, 08:03 AM
Originally posted by Dave Clark
Aw, zip it! :p Don't pretend you're so smart -- or you wouldn't have asked this:
But, for me, it is actually worse than that. Until yesterday, I thought that ++x was invalid syntax. :D But I looked it up, yesterday when I posted, so that I wouldn't look like an idiot stating that it was wrong to do it that way. ;) But, when I looked it up, I missed the part about what is the difference between the two of them.
That's all...
Dave
i know's how it works in c++!!
after u told me that i am mistaking (at the first answer) and i see u as more experiense js dveloper i toke your word as is!
now i know that i was correct!