From 305ab59d36bb1f512e8186a4bf303e947896ed36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E9=87=91=E6=98=9F?= <3441777097@qq.com> Date: Mon, 10 Oct 2022 22:10:12 +0800 Subject: [PATCH 1/2] 10 --- ...60\347\273\204\347\273\203\344\271\240.md" | 51 +++++++++++ .../10.10-\346\225\260\347\273\204.md" | 90 +++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 "10\344\275\231\351\207\221\346\230\237/\344\275\234\344\270\232/JavaScript\346\225\260\347\273\204\347\273\203\344\271\240.md" create mode 100644 "10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" diff --git "a/10\344\275\231\351\207\221\346\230\237/\344\275\234\344\270\232/JavaScript\346\225\260\347\273\204\347\273\203\344\271\240.md" "b/10\344\275\231\351\207\221\346\230\237/\344\275\234\344\270\232/JavaScript\346\225\260\347\273\204\347\273\203\344\271\240.md" new file mode 100644 index 0000000..e4eadba --- /dev/null +++ "b/10\344\275\231\351\207\221\346\230\237/\344\275\234\344\270\232/JavaScript\346\225\260\347\273\204\347\273\203\344\271\240.md" @@ -0,0 +1,51 @@ +```java +var text ='I love teaching and empowering people. I teach HTML, CSS, JS,.000 React, Python.' +//将上述字符串去除标点空格后统计有多少个单词 +console.log("原字符串长度:"+text.length); +var kong = text.split(' ').length-1; +console.log('空格的个数'+kong); +var dou= text.split(',').length-1; +console.log('逗号的个数:'+dou); +var dian = text.split('.').length-1; +console.log('点号的个数:'+dian); +var sum = text.length-kong-dou-dian; +console.log('单词的个数:'+sum); + +const arr = [87,85,74,70,43,59,65] +// 0.将元素65 与43 调换位置 + +// 1.移除第一个元素87,并在开头添加 元素86 +arr.shift() +arr.unshift(86) +console.log(arr); +// 2.移除最后一个元素43, 并在末尾添加1 +arr.pop() +arr.push(1) +console.log(arr); +// 3.在 70 65 之间插入 元素 68 +var a = arr.indexOf(70,0); +var b = arr.indexOf(65,0); +arr.splice(a+1,0,68); +console.log(arr); +// 4.删除元素65 +const del = 65; +const arr1 = arr.filter(item=>item!= del) +console.log(arr1); +// 5.使用map返回一个新的数组new_arr,要求新数组new_arr比原来数组大2 +var new_arr = arr.map(Myfunction) +function Myfunction(value,index,array) +{ + return value*4 +} +console.log(new_arr); +// 6.筛选数组new_arr返回new_arr1,要求new_arr1: 能被2整除 +var new_arr1 = []; +for (let index = 0; index < arr.length; index++) { + if(arr[index]%2==0) + { + new_arr1.push(arr[index]) + } +} +console.log(new_arr1); +``` + diff --git "a/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" "b/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" new file mode 100644 index 0000000..53b74fe --- /dev/null +++ "b/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" @@ -0,0 +1,90 @@ +#### String常用方法 + +```javascript +let js = "JavaScript" +1.获取字符串的长度:js.length +2.将英文字母全转为大写:js.toUpperCase() +2.1将英文字母全转为小写:js.toLowerCase() +3.截取字符串:substr(startIndex,counts) startIndex:起始的索引位置 +counts:截取字符串的个数 +3.1截取字符串:substring(startIndex,endIndex) startIndex:起始索引位置 endIndex:截取索引位置(不包含)\ +4.拆分字符串:split() +5.去除开头或者结尾的空格:trim() +6.查看是否字符串中是否包含includes() +``` + +#### 数据类型转换 + +```javascript +将字符串转为整型:parseInt() +将字符串转为浮点型:parseFloat() +``` + +#### 常量 + +```javascript +const a = 6; //常量不能修改 +a = 66; +console.log(a); +``` + +#### 数组 + +```javascript +var arr = [1,2,3,4,5,6] +1.join():把数组所有元素放入一个字符串 +var str = arr.join('#') +2.concat(): +const firstList = [1, 2, 3]; +const secondList = [4, 5, 6]; +const thirdList = firstList.concat(secondList); +3.slice():参数个数:0 1 2 返回一个数组对象 + +4.splice():接收 0 2 多 个参数 表示移除,替换元素 +4.1:splice(start,end):左右都闭合,都能取到 +arr.splice(1,3) +arr.splice(1,3,2,2,2); //(1,3):移除下标1-3的元素,(2,2,2):要替换的元素 +5.push():末尾添加 +arr.push(); +6.pop():末尾删除 +arr.pop(); +7.unshift():开头添加 +arr.unshift(); +8.shift:开头删除 +arr.shift(); +9.reverse():反转数组的元素顺序 +arr.shift(); +10.forEach():为数组中每个元素调用对应函数, 遍历数组 +const arr2 = [1,2,3,4,5,6]; +arr2.forEach( + function (item,index,arr){ + item + 2 + console.log(item); + console.log('下标'+index); + } +) +11.map:为数组中每个元素调用对应函数,返回一个新的数组 +const arr3 = arr2.map( + function(item){ + return item*2 + } +) +console.log(arr3); +12.filter(过滤):筛选符合条件的元素,返回一个新数组 +const arr4 = arr2.filter( + function (item) { + if(item%2==0){ + return item + } + } +) +console.log(arr4); +13.reduce():归纳汇总 +const varr = arr2.reduce( + function (v1,v2){ + return v1*v2 + } +) +console.log(varr); +``` + -- Gitee From 39e35e32cf68e38107447664a6c999a30e0eb672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E9=87=91=E6=98=9F?= <3441777097@qq.com> Date: Mon, 10 Oct 2022 22:14:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../10.10-\346\225\260\347\273\204.md" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" "b/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" index 53b74fe..ddf7c6d 100644 --- "a/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" +++ "b/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260/10.10-\346\225\260\347\273\204.md" @@ -7,7 +7,7 @@ let js = "JavaScript" 2.1将英文字母全转为小写:js.toLowerCase() 3.截取字符串:substr(startIndex,counts) startIndex:起始的索引位置 counts:截取字符串的个数 -3.1截取字符串:substring(startIndex,endIndex) startIndex:起始索引位置 endIndex:截取索引位置(不包含)\ +3.1截取字符串:substring(startIndex,endIndex) startIndex:起始索引位置 endIndex:截取索引位置(不包含) 4.拆分字符串:split() 5.去除开头或者结尾的空格:trim() 6.查看是否字符串中是否包含includes() @@ -39,7 +39,6 @@ const firstList = [1, 2, 3]; const secondList = [4, 5, 6]; const thirdList = firstList.concat(secondList); 3.slice():参数个数:0 1 2 返回一个数组对象 - 4.splice():接收 0 2 多 个参数 表示移除,替换元素 4.1:splice(start,end):左右都闭合,都能取到 arr.splice(1,3) -- Gitee