<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
//javascript实现交换
var a = "stupid";
var b = "idiot";
var c = ["stupid","idiot"];
//代码段1:可以实现a,b两个字符对象引用地址的交换
var temp;
temp = a;
a = b;
b = temp;
//代码2:可以实现a,b两个字符对象引用地址的交换
b = [a, a = b][0];
//代码3:可以实现a,b两个字符对象引用地址的交换
var swap = function (x){return x};
b = swap(a, a=b);
//对array里的内容进行交换,此方法不能进行引用地址交换
function swapping(c){
var temp;
temp = c[0];
c[0] = c[1];
c[1] = temp;
return c;
}
swapping(c);
</script>
</body>
</html>
javascript实现交换数据
最新推荐文章于 2023-11-10 15:23:08 发布