javascript实现交换数据

来源:互联网 发布:质数算法 编辑:程序博客网 时间:2024/05/22 06:10
<!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>

0 0
原创粉丝点击