zsydgithub 1 year ago
parent
commit
7b1230ad6c
4 changed files with 283 additions and 0 deletions
  1. 44 0
      JS/10_对象.html
  2. 59 0
      JS/11_数据类型.html
  3. 73 0
      JS/12_数组的方法.html
  4. 107 0
      JS/13_字符串的方法.html

+ 44 - 0
JS/10_对象.html

@@ -0,0 +1,44 @@
+<!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>
+    //引用数据类型  object
+    var a = [1,2,3,4]
+    console.log(a[0])
+
+    var b = {
+      name: 'zs',
+      age: 18
+    }
+    console.log(b)//object
+    // console.log(b.name)
+    b.name = 'lisi'
+    console.log(b)
+
+    var person = new Array()
+    person['age'] = 20
+    person['name'] = 'xiaoming'
+    console.log(person)
+    //Array是一个特殊的Object
+
+
+    var a1 = 123
+    var a2 = '123'
+    var a3 = true
+    var a4 = undefined
+    var a5 = [1,2,3]
+    var a6 = {
+      name: 'xiaohong'
+    }
+
+    console.log(typeof a5)
+
+  </script>
+</body>
+</html>

+ 59 - 0
JS/11_数据类型.html

@@ -0,0 +1,59 @@
+<!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>
+    //基本数据类型:number string boolean undefined null
+    //引用数据类型:object
+
+    // var a = 4
+    // b = a
+    // b = 10
+    // console.log(a)
+    // console.log(b)
+
+
+    // var a = [1,2,3,4]
+    // b = a
+    // b[0] = 999
+    // console.log(a)
+    // console.log(b)
+
+    // var a = {
+    //   name: 'zs',
+    //   age: 30
+    // }
+    // b = a
+    // b.name = 'peiqi'
+    // console.log(a)
+    // console.log(b)
+
+    var b = 3
+    var c = {
+      name: 'xiaohong'
+    }
+    function num() {
+      console.log(b)
+      var b = 11
+      console.log(b)
+      console.log(c.name)
+      c.name = 'lisi'
+      console.log(c.name)
+      b = 12
+    }
+    console.log(b)
+    num()
+    console.log(b)
+
+    //3 undefined  11 xiaohong  lisi  3
+  </script>
+</body>
+
+</html>

+ 73 - 0
JS/12_数组的方法.html

@@ -0,0 +1,73 @@
+<!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>
+    //toString() 把数组转换为数组值(逗号分隔)的字符串
+    // var fruits = ["Banana", "Orange", "Apple", "Mango"];
+    // var a = fruits.toString()
+    // console.log(a)
+
+    //join() 方法也可将所有数组元素结合为一个字符串。
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // var a = fruits.join('*')
+    // console.log(a)
+
+    //pop() 方法从数组中删除最后一个元素
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // var a = fruits.pop()
+    // console.log(a)
+    // console.log(fruits)
+
+    //push() 方法(在数组结尾处)向数组添加一个新的元素
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // // fruits.push('kiwi')
+    // console.log(fruits.push('kiwi'))
+
+    //shift() 方法会删除首个数组元素,并把所有其他元素“位移”到更低的索引
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // // fruits.shift()
+    // console.log(fruits.shift())
+
+    //unshift() 方法(在开头)向数组添加新元素,并“反向位移”旧元素
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // console.log(fruits.unshift('kiwi'))
+
+    //使用 JavaScript delete 运算符来删除
+    //使用 delete 会在数组留下未定义的空洞。请使用 pop() 或 shift() 取而代之
+    // var fruits = ["Banana", "Orange","Apple", "Mango"];
+    // delete fruits[0]
+    // console.log(fruits)
+
+    //splice() 方法可用于向数组添加新项
+    //splice(第一个参数代表添加元素的位置,第二个代表删除元素的个数)
+    // var fruits = ["Banana", "Orange"  ,"Apple", "Mango"];
+    // // fruits.splice(2,0,'kiwi','pear')
+    // // console.log(fruits)
+
+    // fruits.splice(0,2)
+    // console.log(fruits)
+
+    //concat() 方法通过合并(连接)现有数组来创建一个新数组
+    // var myGirls = ["Cecilie", "Lone"];
+    // var myBoys = ["Emil", "Tobias", "Linus"];
+    // var myChildren = myGirls.concat(myBoys)
+    // console.log(myChildren)
+
+
+    //slice() 方法用数组的某个片段切出新数组。
+    var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
+    var num = fruits.slice(1,3) //[1,3)
+    console.log(fruits)
+    console.log(num)
+  </script>
+</body>
+
+</html>

+ 107 - 0
JS/13_字符串的方法.html

@@ -0,0 +1,107 @@
+<!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>
+    //length 属性返回字符串的长度
+    // var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    // var nn = txt.length
+    // console.log(nn)
+
+    //indexOf() 方法返回字符串中指定文本首次出现的索引(位置)
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.indexOf("China");
+    // console.log(pos)
+
+    //lastIndexOf() 方法返回指定文本在字符串中最后一次出现的索引:
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.lastIndexOf("China");
+    // console.log(pos)
+    //如果未找到文本, indexOf() 和 lastIndexOf() 均返回 -1。
+
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.indexOf("China", 18);
+    // console.log(pos)
+
+    // var str = "The full name of China is the People's Republic of China.";
+    // var pos = str.lastIndexOf("China", 50);
+    // console.log(pos)
+
+    //search() 方法搜索特定值的字符串,并返回匹配的位置
+    // var str = "The full name of China is the People's is Republic of China.";
+    // var pos = str.search("is");
+    // console.log(pos)
+
+    //search() 方法无法设置第二个开始位置参数。
+    //indexOf() 方法无法设置更强大的搜索值(正则表达式)
+
+    //slice() 提取字符串的某个部分并在新字符串中返回被提取的部分
+    // var str = "Apple, Banana, Mango";
+    // var res = str.slice(7, 13);
+    // console.log(res)
+
+    //substring() 类似于 slice()  无法接受负的索引
+    // var str = "Apple, Banana, Mango";
+    // var res = str.substring(7, 13);
+    // console.log(res)
+
+    //substr() 类似于 slice()  第二个参数规定被提取部分的长度
+    // var str = "Apple, Banana, Mango";
+    // var res = str.substr(7, 6);
+    // console.log(res)
+
+    //replace() 方法用另一个值替换在字符串中指定的值
+    // str = "Please visit Microsoft!";
+    // var n = str.replace("Microsoft", "W3School");
+    // console.log(n)
+
+    //replace() 只替换首个匹配
+    // str = "Please visit Microsoft and Microsoft!";
+    // var n = str.replace("Microsoft", "W3School");
+    // console.log(n)
+
+    //大小敏感
+    // str = "Please visit Microsoft!";
+    // var n = str.replace("MICROSOFT", "W3School");
+    // console.log(n)
+
+    //通过 toUpperCase() 把字符串转换为大写
+    // var text1 = "Hello World!";       // 字符串
+    // var text2 = text1.toUpperCase();  // text2 是被转换为大写的 text1
+    // console.log(text2)
+
+    //通过 toLowerCase() 把字符串转换为小写
+    // var text1 = "Hello World!";       // 字符串
+    // var text2 = text1.toLowerCase();  // text2 是被转换为小写的 text1
+    // console.log(text2)
+
+    //concat() 连接两个或多个字符串:
+    // var text1 = "Hello";
+    // var text2 = "World";
+    // text3 = text1.concat(" ", text2);
+    // console.log(text3)
+
+
+    //trim() 方法删除字符串两端的空白符
+    // var str = "       Hello World!        ";
+    // alert(str.trim());
+
+    //charAt() 方法返回字符串中指定下标(位置)的字符串:
+    // var str = "HELLO WORLD";
+    // console.log(str.charAt(0)); 
+
+    //charCodeAt() 方法返回字符串中指定索引的字符 unicode 编码:
+    var str = "HELLO WORLD";
+
+    console.log(str.charCodeAt(0)); 
+  </script>
+</body>
+
+</html>