<!-- Part of javalessons.com (c)2007 SEMM(NL) All rights reserved Author:P.Hamaker For educational purposes only.-->
<html>
<head>
<script type="text/javascript">
var arr = null ;

function splitit()
{
 var str = 'Amsterdam&Ontario&istanbul&New York';
 arr = str.split( '&' );
 arr.sort();
 showarr();
 document.getElementById('bt1').disabled=true;
}
function showarr()
{
 var tx = document.getElementById('tx3');
 tx.value = '' ;
 for ( var i = 0 ; i < arr.length ; i++ )
 {
  tx.value +=  i + ':' + arr[i] + ' ' ;
 }
}
function popit()
{
 document.getElementById('tx1').value = arr.pop();
 showarr();
}
function addit()
{
 arr.push( document.getElementById('tx1').value ) ;
 showarr();
}
function repl()
{
 var inx = document.getElementById('tx2').value ;
 arr[inx] = document.getElementById('tx1').value ;
 showarr();
}
function salg( a, b )
{
 if ( a.toLowerCase() > b.toLowerCase() ) return 1 ;
 if ( a.toLowerCase() < b.toLowerCase() ) return -1 ;
 return 0 ;
}
function sortic()
{
 arr.sort( salg ) ;
 showarr();
}
function notcalled()
{
 var somearr = new Array(50);
 somearr[0] = 'Magnet' ;
 somearr[1] = 'Energy' ;
 //etc.
}
</script>
</head>

<body style="font-family: sans-serif; font-size: large; margin-left: 20; margin-top: 30">
JavaScript Lesson arrays
<form>City
<input type="text" id="tx1" maxlength="20" size="22">
Index
<input type="text" id="tx2" maxlength="3" size="5">
Array
<input type="text" id="tx3" size="70" readonly="readonly">
<p>
<input id="bt1" type="button" value="Init" onclick="splitit()">
<input type="button" value="Pop" onclick="popit()">
<input type="button" value="Add" onclick="addit()">
<input type="button" value="Replace" onclick="repl()">
<input type="button" value="Sort" onclick="sortic()">
<input type="reset" value="Clear" onclick="bt1.disabled=false">
</form>
</body></html>