Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing String As An Array

Status
Not open for further replies.

snakehips2000

Programmer
Nov 10, 2003
95
GB
I've got problems with the following JavaScript code. Although the array is seemingly created, I'm unable to access the individual elements (in this case, the first one 'uno'). Instead the browser displays the whole array, i.e. 'uno', 'dos', 'tres'. When I replace "document.writeln(arr2[0]);" with "document.writeln(arr2[1]);" I receive "undefined":

<script language = "Javascript">

function DuplicateRows(arry) {
var str=arry.substring(1, arry.length-1);
var arr2=new Array(str.split(","));
document.writeln(arr2[0]);
}

DuplicateRows("~'uno', 'dos', 'tres'~");
</script>

Any help much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top