准备测试数据
var data= [{name:"Jackie",id: "122"}, {name:"Tony2",id: "121"}, {name:"Tony",id: "121"}];
find 查找 返回第一个符合条件的结果
data.find(user=>user.id==='121')--结果
{name: "Tony2", id: "121"}
filter 过滤 返回所有符合条件的结果
data.filter(user=>user.id==='121')--结果
(2) [{…}, {…}]
0: {name: "Tony2", id: "121"}
1: {name: "Tony", id: "121"}
length: 2
__proto__: Array(0)
sort 按指定条件排序
--根据id 由小到大排序data.sort((a, b) => (a.id > b.id) ? 1 : ((b.id > a.id) ? -1 : 0))--结果
(3) [{…}, {…}, {…}]
0: {name: "Tony2", id: "121"}
1: {name: "Tony", id: "121"}
2: {name: "Jackie", id: "122"}
length: 3
__proto__: Array(0)