add 5.4 array
This commit is contained in:
		
							
								
								
									
										12
									
								
								5.4ArrayMethod/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								5.4ArrayMethod/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|     <meta charset="UTF-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||
|     <title>Document</title> | ||||
| </head> | ||||
| <body> | ||||
|     <script src="./t.js"></script> | ||||
|      | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										35
									
								
								5.4ArrayMethod/t.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								5.4ArrayMethod/t.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| array = ["Bilbo", "Gandalf", "Nazgul"]; | ||||
| array.forEach((item, index, array) =>{ | ||||
|     console.log(`${item} is at index ${index} in ${array}`) | ||||
| }); | ||||
|  | ||||
| console.log(`arr.indexOf(Bilbo): ${array.indexOf("Bilbo")}`) | ||||
| console.log(`arr.indexOf(Bilbo): ${array.includes("Bilbo")}`) | ||||
|  | ||||
| let fruits = ['Apple', 'Orange', 'Apple'] | ||||
| console.log(`fruits.indexOf('Apple'): ${fruits.indexOf('Apple')}`) | ||||
| console.log(`fruits.lastIndexOf('Apple'): ${fruits.lastIndexOf('Apple')}`) | ||||
|  | ||||
| // arr.find(fn) | ||||
| let users = [ | ||||
|     {id: 1, name: "xingzhesun"}, | ||||
|     {id: 2, name: "zhexingsun"}, | ||||
|     {id: 3, name: "sunxingzhe"}, | ||||
| ]; | ||||
|  | ||||
| let user1 = users.find(item => item.id == 1); | ||||
| let user2 = users.findLastIndex(item => item.id == 1); | ||||
| console.log(user1.name); | ||||
| console.log(user2.name); | ||||
|  | ||||
| // arr.filter | ||||
| let someUsers = users.filter(user => user.id < 3); | ||||
| console.log(someUsers) | ||||
| someUsers = users.filter(function(item, index, array){ | ||||
|     if (item.id < 3){ | ||||
|         return true; | ||||
|     } | ||||
| }) | ||||
| console.log(someUsers); | ||||
|  | ||||
| // arr.map(fn) | ||||
		Reference in New Issue
	
	Block a user