标签:acs space for file charset cal var bsp log
27array6.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script> // 解构赋值 解析数组或对象的结构为不同的变量提取值 //var name = "along"; //var age = 32; var [name,age] = ["along",32]; console.log(name); console.log(age); //var [x,y,z] = [1,[2.2,2.3]]; //var [x,[y,z]] = [1,[2.2,2.3]]; //console.log(x,y,z); // 1 [2.2,2.3] undefined var [json,arr,num] = [{a:10,b:20},[1,2,3],10]; var [,,x=4] = [1,2];//传默认值 console.log(x); var [x,...y] = [10,20,30,40];// 剩余项 console.log(x,y);// 10 [20,30,40] var arr = [1,2,3]; var [...arr1] = arr; // 克隆数组 console.log(arr1); var x = 10, y = 20; /* var temp = x; x = y; y = temp; */ [x,y] = [y,x]; console.log(x,y); </script> </body> </html>
27array7.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script> var arr = [12, 5, 4, 6, 11, 9]; /* 升序 冒泡排序 12,5,4,6 第一轮 比较3次 得到最大值 5 12 4 6 5 4 12 6 5 4 6 12 第二轮 5 4 6 比较2次 得到第二大的值 4 5 6 12 4 5 6 12 第三轮 比较1次 得到第三大的值 4 5 i j 0 3 0~1 1~2 2~3 1 2 0~1 1~2 .. arr.length-1-i */ console.log(bubbleSort(arr)); function bubbleSort(arr) { // 定义循环 控制轮数 var temp = 0; for (var i = 0; i < arr.length - 1; i++) { // 每一轮 进行比较若干次 0 1 2 for (j = 0; j < arr.length - 1 - i; j++) { // 相邻两数比较 if (arr[j] < arr[j + 1]) { /* temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; */ [arr[j],arr[j+1]] = [arr[j+1],arr[j]]; } } } return arr; } // 选择排序 /* 升序 12,5,4,6 5 12 4 6 4 12 5 6 */ </script> </body> </html>
03JavaScript程序设计修炼之道 2019-06-04_fe-js-044es6解构赋值之数组解构_2019-06-06_20-10-17 解构赋值、数组排序法
标签:acs space for file charset cal var bsp log
原文地址:https://www.cnblogs.com/HiJackykun/p/11140964.html