99 lines
2.3 KiB
HTML
99 lines
2.3 KiB
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 a = 3, b = 4, c = 5;
|
||
|
||
// // 条件表达式两边的结果必须为 true,才回返回 true,否则都为flase
|
||
// console.log(a != b && b != c); //false true
|
||
|
||
// // 条件表达式两边的结果 只要有一个为true,那么直接返回为true
|
||
// // 两个都为false,false
|
||
// console.log( a == c || b == a ); // true
|
||
|
||
|
||
// console.log( !(a==c) );
|
||
|
||
// 数组
|
||
// 概念:类似数学里面的集合,他是众多数据(string,number,boolean,undefined,null,object,array)的的集合
|
||
// 下标:永远从0开始
|
||
|
||
// 定义 三种方式
|
||
|
||
// 1:
|
||
// var num = new Array();
|
||
// num[0] = 1;
|
||
// num[1] = "张三";
|
||
// num[2] = 3;
|
||
// num[10] = "我是10"
|
||
// console.log(num);
|
||
|
||
// 2
|
||
// var num = new Array(1,'张三',3,'我是10');
|
||
// console.log(num);
|
||
|
||
// 3
|
||
var num = [ 1,'张三',3,'我是10', '哈哈哈' ];
|
||
console.log(num);
|
||
|
||
// 数组的增删改查
|
||
// 增
|
||
// 1:通过下标新增数据 low
|
||
//num[5] = "23"
|
||
|
||
// 2: 获取数组长度访问数组添加新值
|
||
// num[num.length] = "sdddd"
|
||
|
||
// 3: 系统内置的方法 push 向最后追加数据
|
||
// num.push("push追加的数据","你好")
|
||
// 系统内置的方法 unshift 向开始追加数据
|
||
// num.unshift("unshift追加的数据","顶顶顶顶")
|
||
// console.log(num);
|
||
|
||
// 删
|
||
// 1: 构造新数组然后循环判断数据 low
|
||
// var del = '张三', newArr = [];
|
||
// num.forEach(function(val,index,arr){
|
||
// if(val != del) {
|
||
// newArr.push(val)
|
||
// }
|
||
// })
|
||
|
||
// 2: 使用 splice 对数组进行删除,注意 第一个参数可以是正负数
|
||
// num.splice(2,1,"splice添加的数据")
|
||
// console.log(num);
|
||
|
||
// 改
|
||
// 1
|
||
// num[1] = "李四"
|
||
// console.log(num);
|
||
|
||
// 2:使用循环进行批量改操作
|
||
|
||
// 查
|
||
// 1
|
||
console.log(num[1]);
|
||
|
||
// 2: 使用循环进行批量查操作
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</script>
|
||
</body>
|
||
</html> |