关于数组的一些方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//用于删除数组中指定的元素id
this.list.filter(item => item.id != id)

//用于累加数组的某个属性值
this.list.reduce((sum,item)=>sum+item.num,0)

//用于提取数组中的部分数据
this.list.slice(start, end)

//用于给数组的开头添加元素
this.list.unshift(element1, element2, ..., elementN)

//用于给数组的末尾添加元素
this.list.push(element1, element2, ..., elementN)

//用于将数组中的所有元素连接成字符串,元素之间用指定的分隔符进行分隔
const array = ['apple', 'banana', 'orange'];
const result = array.join(', '); // 结果:'apple, banana, orange'
1
2
3
4
5
6
7
// 普通函数
const add = function(a, b) {
return a + b;
};

// 箭头函数
const addArrow = (a, b) => a + b;

回调函数(Callback Function)是指一个函数作为参数传递给另一个函数,并在特定事件发生时被调用