Why not use an array ?
var myVar = new Array();
var myvarcount = 10;
for(int i = 0; i myvarcount; i++) {
myVar[i] = I am number : + i;
}
On Tue, Jun 9, 2009 at 4:35 PM, simon si...@uvfx.tv wrote:
I have some simple variables
$.myvariable1
$.myvariable3
$.myvariable2
now I would
sorry i had a syntax error
heres the code
see just declare an array
declare the maximum number you want
then loop through them one by one asigning a number to each one :)
var myVar = new Array(); // declare array
var myvarcount = 10; // maximum vars
for(var i = 0; i myvarcount; i++) { //
yeah. so its either an array or object.
but if you really wanna get messy and have variables like you listed
you could echo it out through php script or do an asp response.write
however that uses up server side memory to generate JavaScript on run time.
so i woul say Array or Object :)
On
try to use object like this:
var myObject={};
var count=10;
for(var i=0;icount;i++)
{
myObject['value_at_'+i.toString()]=value at +i.toString();
}
or
assign value like
var index=5;
myObject['value_at_'+index.toString()]= this is value at 5;
alert(myObject['value_at_5']); //display this is
yeah agree . Its depend on the requirement if some one want to manipulate
variable with random number than object is useful otherwise array is good
option.
~N a R e N
On Tue, Jun 9, 2009 at 8:46 PM, waseem sabjee waseemsab...@gmail.comwrote:
yeah. so its either an array or object.
but
thanks for all the options guys, I did think of arrays but I got a lot
of updating to do if so and just to see if that could be done.
luckly I only have three variables so not too much of an issue.
I also was going to use asp scripting but again if others take on my
work here it gets more
what type of updating are you gonna do ? you mean to post these variables ?
On Tue, Jun 9, 2009 at 5:43 PM, simon si...@uvfx.tv wrote:
thanks for all the options guys, I did think of arrays but I got a lot
of updating to do if so and just to see if that could be done.
luckly I only have
what i havev done is constructe my page and all things working etc etc
but long winded, then what I do is then begin to reduce the code down
that is on that page whether it be asp, php of js, this way I learn
more about the script and in future do that method instead and then my
coding gets
On Jun 9, 9:35 am, simon si...@uvfx.tv wrote:
$.myvariable1
$.myvariable3
$.myvariable2
now I would like to add the number part of the variable to it
dynamically.
var i=1;
$['myvariable'+i] === $.myvariable1
See: http://www.javascripttoolbox.com/bestpractices/#squarebracket
Matt Kruse
thanks mark, I knew there was a way as its similar to flash as
coding , just I was putting the sqr brackets in wrong place
thanks again
Hi Narendra,
I'm wondering why you use toString() method here?
I think 'value_at_' + i
would also work fine
On Jun 9, 10:09 pm, Narendra sisodiya naren.sisod...@gmail.com
wrote:
try to use object like this:
var myObject={};
var count=10;
for(var i=0;icount;i++)
{
11 matches
Mail list logo