Click to See Complete Forum and Search --> : using arrays


st3
09-10-2003, 02:44 PM
i use an array to save different informations, which is putting in the right place by "document.getElementById('content').innerHTML = test".

but between my information pieces are "," and i don't know why and how to erase them.

anny solution for me, the java script beginner?

thanks a lot.

<html>
<head>

<script type="text/javascript">
<!--

function testfunc(){

var test = Array()
test[0] ="test1"
test[1] ="test2"
test[2] ="test3"

document.getElementById('content').innerHTML = test

}
//-->
</script>
</head>

<body onLoad="testfunc()">

<div id="content">
</div>

</body>
</html>

Charles
09-10-2003, 02:56 PM
In JavaScript whenever you use an Array, or any other Object, a secret method, toString(), is called. You can either over write this method to your liking,

Array.prototype.toString = function () {return this.join('_foo_')},

or you can join the Array elements at the time of the assignemt,

document.getElementById('content').innerHTML = test.join('_foo_').

Fang
09-10-2003, 02:56 PM
The "," is the array delimiter. Your array test is test1,test2,test3
normally you wouldn't write out the complete array.
you could write doc..innerHTML=test[0]+test[1]+test[2];
Have a look here (http://www.w3schools.com/js/js_arrays.asp)

st3
09-10-2003, 05:24 PM
thanks a lot. that helps.