arr

你会用哪些JavaScript循环遍历

大兔子大兔子 提交于 2019-12-07 19:04:04
总结JavaScript中的循环遍历 定义一个数组和对象 const arr = ['a', 'b', 'c', 'd', 'e', 'f']; const obj = { a: 1, b: 2, c: 3, d: 4 } for() 经常用来遍历数组元素 遍历值为数组元素索引 or (let i = 0; len = arr.length, i < len; i++) { console.log(i); // 0 1 2 3 4 5 console.log(arr[i]); // a b c d e f } forEach() 用来遍历数组元素 第一个参数为数组元素,第二个参数为数组元素索引,第三个参数为数组本身(可选) 没有返回值 console.log(item); // a b c d e f console.log(index); // 0 1 2 3 4 5 }) 前端全栈学习交流圈:866109386,面向1-3经验年前端开发人员,帮助突破技术瓶颈,提升思维能力,群内有大量PDF可供自取,更有干货实战项目视频进群免费领取。 map() 用来遍历数组元素 第一个参数为数组元素,第二个参数为数组元素索引,第三个参数为数组本身(可选) 有返回值,返回一个新数组 every(),some(),filter(),reduce(),reduceRight()不再一一介绍

js 实现排列组合的打印,

99封情书 提交于 2019-12-07 16:16:27
1 var results = [], result = []; 2 3 function doExchange(arr, index) { 4 5 for (var i = 0; i < arr[index].length; i++) { 6 // 填充第一项 7 result[index] = arr[index][i]; 8 // 判断条件 9 if (index != arr.length - 1) { 10 // 递归 11 doExchange(arr, index + 1) 12 } else { 13 // 结束的时候 14 results.push(result.join('-')) 15 } 16 } 17 } 18 19 var arr = [[1, 2], [3, 4]]; 20 doExchange(arr, 0) // 21 console.log(results) // output: 1-3,1-4,2-3,2-4 交换递归的思想,多写几遍就知道,书读百本其义自见,不明白敲上100遍就懂了 来源: https://www.cnblogs.com/ajaxkong/p/12002113.html

前端学习笔记-JavaScript

强颜欢笑 提交于 2019-12-07 15:17:32
js引入方式:   1、嵌入js的方式:直接在页内的script标签内书写js功能代码。     <script type="text/javascript">alert('hello')</script>   2、外联式引入js:以相对路径的方式引入本地js文件,实现H5、CSS、JS分离。     <script type="text/javascript" src="hello.js"></script> js基本语法:   定义变量:使用var关键字,区分大小写。 var a = 123; 使用js操作属性: 1 <script type="text/javascript"> 2 window.onload = function(){ 3 //通过获取一个标签的id来联系标签 4 var oDiv = document.getElementById('div1');       var oInput01 = document.getElementById('input01');       var aLi = documentsgetElementsByTagName('li');//获取一组标签,使用时可通过下标确定具体使用哪一个 5 //对目标标签进行style属性重写 6 oDiv.style.color = 'red';       aLi[2].style

JSON数组去重复项

拥有回忆 提交于 2019-12-07 00:51:56
JSON数组去重复项 var arr = [ {"name" : "1","value" : "qqq","age" : "10"}, {"name" : "1","value" : "qqq","age" : "10"}, {"name" : "2","value" : "eee","age" : "20"}, {"name" : "4","value" : "rrr","age" : "50"}, {"name" : "5","value" : "ttt","age" : "100"} ]; //方法一 var hash = {}; arr = arr.reduce(function(item, next) { hash[next.name] ? '' : hash[next.name] = true && item.push(next); return item }, []) console.log(arr); //方法二 for (var i = 0; i < arr.length; i++) { for (var j =i+1; j <arr.length; ) { if (arr[i].name == arr[j].name && arr[i].value == arr[j].value && arr[i].age == arr[j].age) {/

第一个java记录

别等时光非礼了梦想. 提交于 2019-12-06 22:49:37
import java.util.Arrays;import java.util.Random;import java.util.Scanner;/** 1. 定义一个长度为5 的int类型数组arr, 提示用户输入5个1-60之间的数字作为数组元素 生成2-10(范围包含2和10)之间的随机数num 比那里数组arr,筛选出数组中的不是num倍数的元素并且输出 */public class Test01 { public static void main(String[] args) { //创建数组 int arr[] = new int[5]; //键盘录入 Scanner scanner = new Scanner(System.in); for (int i = 0; i < arr.length ; i++) { System.out.println("输入5个1-60之间的数字作为数组元素,这是第"+(i+1)+"个"); int next = scanner.nextInt(); arr[i] = next; } System.out.println(Arrays.toString(arr)); //生成2-10(范围包含2和10)之间的随机数num Random random = new Random(); //不包含右边界,所以在2到10之间 int num =

js的reduce方法

北战南征 提交于 2019-12-06 16:23:49
reduce()方法接受一个函数进行累加计算(reduce()对于空数组是不会执行回调函数的) 使用语法: array.reduce(function(total, currentValue, currentIndex, arr), initialValue) total:初始值,或者计算结束后返回的返回值(必需) currentValue:当前元素(必需) currentIndex:当前元素的索引 arr:当前元素所属的数组对象 假如在reduce的回调函数里面没有返回值时 var arr = [5,6,7,8,9] arr.reduce(function(total, currentValue, currentIndex, arr){ console.log('reduce:', total, currentValue, currentIndex, arr) }) 打印出来的结果如下 reduce: 5 6 1 [ 5, 6, 7, 8, 9 ] reduce: undefined 7 2 [ 5, 6, 7, 8, 9 ] reduce: undefined 8 3 [ 5, 6, 7, 8, 9 ] reduce: undefined 9 4 [ 5, 6, 7, 8, 9 ] 由此分析: 当reduce循环时,total的初始值是数组第一位的值,由于没有return的值

二、队列

泪湿孤枕 提交于 2019-12-06 15:00:27
队列 队列介绍 队列是一个有序列表,可以用数组或是链表实现 遵循先入先出原则。即:先存入队列的数据,要先取出,后存入的后取出 数组模拟队列 队列本身是有序列表,若使用数组的结构来存储队列的数据,则队列数组的声明如下图,其中maxSize是该队列的最大容量 因为队列的输入、输出是分别从前后端来处理,因此需要两个变量front及rear分别队列前后端的下标,front会随着数据的取出而改变,而rear则是随着数据的移入而改变 代码: public class ArrayQueue{ private int maxSize; private int front; private int rear; private int[] arr;//用于存放数据 public ArrayQueue(int maxSize) { this.maxSize = maxSize; arr = new int[maxSize]; front = -1; rear = -1; } /** * 判断队列是否满 */ public boolean isFull(){ return rear == maxSize-1; } /** * 判断队列是否为空 */ public boolean isEmpty(){ return rear == front; } /** * 添加数据 */ public void add

Java Array二维数组使用

霸气de小男生 提交于 2019-12-06 13:51:32
二维数组:元素为一维数组的数组 package myArray.arrayarray; /* *二维数组:元素为一维数组的数组 * * 定义格式: * A:数组类型[][] 数组名; (推荐用法) * B:数组类型 数组名[][]; * C:数组类型[] 数组名[]; * 初始化: * A:动态初始化 * 数据类型[][] 数组名 = new 数据类型[m][n]; * m表示二维数组中一维数组的个数 * n表示一维数组的个数 * B:静态初始化 * 数据类型[][] 数组名 = new 数据类型[][]{[元素...],[元素...],[元素...]....}; * 简化格式: * 数据类型[][] 数组名 = {[元素...],[元素...],[元素...]....}; * 其中{}个数表示一维元素m个,"元素..."为一个一维元素中有n个元素 * * 二维数组名配合索引可以获取到每一个一维数组。 *每一个一维数组配合索引名可以获取到数组中的元素。 * *假如我有一个二维数组:arr。 *我要从中获取一维数组:arr[索引] *我要从中获取二维数组的元素:arr[索引][索引] */ public class ArrayArray { public static void main(String[] args) { int[][] arr = {{1,2,3},{4,5,6},

Is this ARR warning causing my 404?

无人久伴 提交于 2019-12-06 13:43:49
I'm getting a 404 during a URL redirect/rewrite, and I'm unable to pin down exactly what's causing it. The warning is: REWRITE_DISABLED_KERNEL_CACHE Here are my rules: <rule name="TFS Redirect" stopProcessing="true"> <match url="^((?!tfs).)*$" /> <conditions> <add input="{HTTP_HOST}" pattern="tfs.domain.com" /> </conditions> <action type="Redirect" url="http://tfs.domain.com/tfs" /> </rule> <rule name="TFS Rewrite" stopProcessing="true"> <match url="^tfs(.*)" /> <action type="Rewrite" url="http://server3:8080/{R:0}" /> </rule> The redirect rule seems to be working, as I get tfs.domain.com/tfs