ShadowIce
05-16-2009, 12:10 PM
Hi all :) I have been doing some research on arrays and how to create multiple, comma seperated strings.
Now I have a small problem that I cant seem to fix. The problem I have is that I can't get rid of the comma after the last array value has been read. and I can't get the prompt to create more than 1 variable name at once..
if there's a way to retrieve the comma seperated list along with the double quotes using only 1 document.write, please help. i need the variables to look like this:
var variable = new Array("comma","seperated","list");
here is the script i created from various resources:
<script>
function name(num){
var vnum;
for(vnum = 1;vnum<=num;vnum++){
var vname = prompt('please enter the name of variable '+vnum+'\: ','');
}
var a = new Array("a","b","c","d");
var b = new Array("e","f","g");
var c = new Array("g","h","i","j");
if(vname != null || vname != ""){
document.write('var '+vname+' = new Array\(');
}
for(var x=0;x<=a.length-1;x++){
if(x.length != a.length-1){
delimiter = ",";
}else{
delimiter = "";
}
document.write('\"'+a[x]+'\"\,');
}
document.write('\)\;');
}
name(4);
</script>
Thank you! :)
~ShadowIce~
Now I have a small problem that I cant seem to fix. The problem I have is that I can't get rid of the comma after the last array value has been read. and I can't get the prompt to create more than 1 variable name at once..
if there's a way to retrieve the comma seperated list along with the double quotes using only 1 document.write, please help. i need the variables to look like this:
var variable = new Array("comma","seperated","list");
here is the script i created from various resources:
<script>
function name(num){
var vnum;
for(vnum = 1;vnum<=num;vnum++){
var vname = prompt('please enter the name of variable '+vnum+'\: ','');
}
var a = new Array("a","b","c","d");
var b = new Array("e","f","g");
var c = new Array("g","h","i","j");
if(vname != null || vname != ""){
document.write('var '+vname+' = new Array\(');
}
for(var x=0;x<=a.length-1;x++){
if(x.length != a.length-1){
delimiter = ",";
}else{
delimiter = "";
}
document.write('\"'+a[x]+'\"\,');
}
document.write('\)\;');
}
name(4);
</script>
Thank you! :)
~ShadowIce~