Javascript:forEach、map、filter、reduce、reduceRight

let array2 = [4, 5, 6];

let array3 = array2.map(value => value * 2)

console.log(array2)

console.log(array3)

运行结果:

在这里插入图片描述

filter的使用

====================================================================

会过滤原数组,返回一个新的数组,过滤条件由filter中表达式决定

基础使用语法:

let array5 = array4.filter(value => 条件)

举例:

let array4 = [1, 2, 3, 4, 5, 6];

let array5 = array4.filter(value => value % 2 === 0)

console.log(array4)

console.log(array5)

运行结果:

在这里插入图片描述

reduce和reduceRight的使用

================================================================================

按照条件对原数组进行操作。

比如对原数组进行求和(求积),或在某数基础上对某一数组进行求和(求积)

基础使用语法:

let result = array6.reduce(函数,初始值,初始值下标,初始值下标数组)

举例:

let array6 = [1, 2, 3, 4];

function getSum(total, num) {

return total + num;

}

let result1 = array6.reduce(getSum);

let result2 = array6.reduce(getSum, 3);

let result3 = array6.reduce(getSum, 1, [1, 2, 3]);

console.log(result1, result2, result3);

运行结果:

在这里插入图片描述

reduceRight()方法的功能和reduce()功能是一样的,不同的是reduceRight()从数组的末尾向前将数组中的数组项做操作。

运算条件:求todo中finished为true的数据个数

finishedCount() {

return this.todos.reduce((total, todo) => total + (todo.finished ? 1 : 0), 0)

}

find和findIndex的使用

============================================================================

find:查询数组中第一个满足某条件的值

findIndex:查询数组中第一个满足某条件的值的下标

基础使用语法:

array7.find((value => 条件))

array7.findIndex((value => 条件))

举例:

let array7 = [

{name:‘1’,sex:‘女’,age:1},

{name:‘2’,sex:‘女’,age:2},

{name:‘3’,sex:‘女’,age:3},

{name:‘4’,sex:‘女’,age:4},

];

console.log(array7.find((value => value.name===‘4’)))

console.log(array7.findIndex((value => value.name===‘4’)))

运行结果:

在这里插入图片描述

keys,values,entries的使用

=================================================================================

ES6 提供三个新的方法 —— entries(),keys()和values() —— 用于遍历数组。它们都返回一个遍历器对象,可以用for…of循环进行遍历,唯一的区别是keys()是对键名的遍历、values()是对键值的遍历,entries()是对键值对的遍历

基础使用语法:

for(let index of 数组.keys()){

console.log(index) // 输出下

真题解析、进阶学习笔记、最新讲解视频、实战项目源码、学习路线大纲
详情关注公中号【编程进阶路】

}

for(let elem of 数组.values()){

console.log(elem) // 输出值

}

for(let [index,elem] of 数组.entries()){

console.log(index,elem) // 输出值和下标

}

举例:

let array8 = [1, 2, 3];

for(let index of array8.keys()){

css

1,盒模型
2,如何实现一个最大的正方形
3,一行水平居中,多行居左
4,水平垂直居中
5,两栏布局,左边固定,右边自适应,左右不重叠
6,如何实现左右等高布局
7,画三角形
8,link @import导入css
9,BFC理解

js

1,判断 js 类型的方式
2,ES5 和 ES6 分别几种方式声明变量
3,闭包的概念?优缺点?
4,浅拷贝和深拷贝
5,数组去重的方法
6,DOM 事件有哪些阶段?谈谈对事件代理的理解
7,js 执行机制、事件循环
8,介绍下 promise.all
9,async 和 await,
10,ES6 的 class 和构造函数的区别
11,transform、translate、transition 分别是什么属性?CSS 中常用的实现动画方式,
12,介绍一下rAF(requestAnimationFrame)
13,javascript 的垃圾回收机制讲一下,
14,对前端性能优化有什么了解?一般都通过那几个方面去优化的?

事件有哪些阶段?谈谈对事件代理的理解
7,js 执行机制、事件循环
8,介绍下 promise.all
9,async 和 await,
10,ES6 的 class 和构造函数的区别
11,transform、translate、transition 分别是什么属性?CSS 中常用的实现动画方式,
12,介绍一下rAF(requestAnimationFrame)
13,javascript 的垃圾回收机制讲一下,
14,对前端性能优化有什么了解?一般都通过那几个方面去优化的?

[外链图片转存中…(img-2iFQn1nY-1720768965356)]

  • 21
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值