本文实例讲述了JS交换变量的方法。分享给大家供大家参考。具体实现方法如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function jh(arr) {
for (var i = 0; i < arr.length / 2; i++) {
var tem = arr[i];
arr[i] = arr[arr.length -i - 1];
arr[arr.length -i - 1] = tem;
}
}
var names = new Array();
names[1] = "tom";
names[2] = "lily";
names[3] = "jek";
jh(names);
alert(names);
</script>
</head>
<body>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。