PDA

View Full Version : external js array



mini_minh
09-05-2005, 08:22 PM
if i have an array in an external js file such as:

var blah = new Array();
blah[0] = "sumthing";
blah[1] = "...";
blah[2] = "=D";

how would i create a document that displays the array?

jscheuer1
09-05-2005, 08:32 PM
document.write(blah.toString())

mini_minh
09-05-2005, 08:37 PM
thanx a lot ^^

mini_minh
09-06-2005, 12:52 AM
sorry but another question on arrays...just say my array was:
var answer = new Array();
answer[0] = "yes";
answer[1] = "no";
answer[2] = "maybe";
answer[3] = "yes";
answer[4] = "yes";

how would i display only the values that are "yes"?

jscheuer1
09-06-2005, 04:37 AM
This is sort of silly because there are many ways to do this and I have no idea why you are doing it. That would influence my choice of methods. This is one way:

var str=''
for (var i_tem = 0; i_tem < answer.length; i_tem++)
if ( answer[i_tem]=='yes' )
str += answer[i_tem]+' '
document.write(str)