JavaScript中用函数的方法实现翻转数组

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function reverse(arr)
        {
            var newarr=[];
            for(var i=arr.length-1;i>=0;i--)
            {
                newarr[newarr.length]=arr[i];
            }
            return newarr;
        }
        var re=reverse([4,5,23,53,52,42]);
        console.log(re);
       
    </script>
</body>
</html>

上一篇:再次简单明了总结flex布局,一看就懂...


下一篇:【reverse】逆向1 数据宽度