js笔记

js

js函数

1.console.dir()
查看数据内容。

字符串函数

1.charCodeAt()、fromCharCode()
let str="文字";
console.log(str.charCodeAt(0));//查看unicode
console.log(String.fromCharCode());

25991

2.lastIndexOf()、indexOf()

查找子字符串

数组函数

1.push()、pop()、unshift()、shift()

push:向末尾添加,可添加多个,返回值为数组改变后长度。
pop:从队尾删除一个,返回删除的值。
unshift:从前面添加,可添加多个,返回数组改变后的长度。
shift:从前面删除一个,返回删除的值。

2.splice()

删除:1,2之间的值 返回值为删除的值
替换:1,2,‘a’,‘b’ 返回值为删除的值
添加:1,0,‘a’,‘b’,‘c’ 返回值为空

3.sort()

如果提供参数(函数),我们可以指定排序的规则

let num = [6,50,12,40];
num.sort((a,b)=>{return a - b;});// return b - a(倒序)
console.log(num);

·>(4) [6, 12, 40, 50]

随机排序

let num = [6,50,12,40];
num.sort((a,b)=>{return Math.random() - 0.5;});// return b - a(倒序)
console.log(num);
4.forEach()、filter()、map()、reduce()、some()、every()
函数返回值参数功能
forEach()undifinedfunction(ele,index,arr){},thisArg遍历所有元素
filter()function判断为true的元素集合function(ele,index,arr){},thisArg筛选
map()function处理过的元素集合function(ele,index,arr){},thisArg处理
reduce()resultfunction(result,ele,index){},intValue计算所有
every()booleanfunction(ele,index,arr){},thisArg全部符合
some()booleanfunction(ele,index,arr){},thisArg有一个符合
- callback(ele)  函数
      - ele :循环过程中的每一位元素
      - index: 当前循环的元素对应的下标值
      - arr :调用forEach的当前数组
- thisArg: 控制当前callback中的this指向

json

1.parse()、stringify()
let obj = {
   name:"key"
}
let _json1 = JSON.stringify(obj);
let _json2='{"key":123}';
console.log(JSON.parse(_json1),JSON.parse(_json2));

·>{name: “key”}·>{key: 123}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值