JavaScript Tutorial/Array/Join
Версия от 18:52, 25 мая 2010; (обсуждение)
Array.join()
Syntax
array.join()
array.join(string)
Join elements in an array
<html>
<head>
<title>Using the sort() method</title>
<script type="text/javascript" language="javascript">
<!-- //
function SortElements(){
var colors = new Array("red","blue","green");
colors.sort();
var cj = colors.join(", ");
alert("The sorted array contains: " + cj);
}
// -->
</script>
</head>
<body onload="SortElements()">
</body>
</html>
Seeming success in copying an array
<html>
<head>
<title>Seeming success in copying an array</title>
<script type="text/javascript" language="javascript">
<!-- //
function CopyArray(){
var myArray = new Array(1,2,3);
var myCopy = myArray;
var ma = myArray.join(", ");
var mc = myCopy.join(", ");
alert(ma);
alert(mc);
}
// -->
</script>
</head>
<body onload="CopyArray()">
</body>
</html>