可以直接获取数组里面的键值
console.log(schedule);
console.log(schedule.map(v => v.date));

schedule.find(item => item.date === fullDate)
可以直接用schedule里面date值,来跟fullDate值来比对,有则返回schedule对应的值,没有则返回undefined。fullDate的值如下

map更多用法
可直接去网页查看
https://comate.baidu.com/zh/page/rco0g9fwsn2#11
map()是JavaScript数组的核心高阶函数,用于遍历数组并返回新数组而不修改原数组
。本文将系统解析其语法特性、典型应用场景及与相关方法的对比。
核心特性与语法
基础语法
const newArray = array.map((currentValue, index, array) => { // 返回处理后的值 }, thisArg); // 可选参数
- 参数说明:
currentValue:当前处理的元素
index(可选):当前元素的索引
array(可选):调用map的数组
thisArg(可选):回调函数的this上下文
核心特性
- 不修改原数组:返回新数组,原数组保持不变
- 一一映射:新数组长度与原数组相同
- 链式调用:支持与
filter()、reduce()等方法的链式操作
典型应用场景
基础数据转换
// 数字数组翻倍 const numbers = [1, 2, 3]; const doubled = numbers.map(num => num * 2); // [2, 4, 6] // 对象属性提取 const users = [{id:1,name:'Alice'},{id:2,name:'Bob'}]; const names = users.map(user => user.name); // ['Alice', 'Bob']
格式化数据
// 价格格式化 const prices = [19.99, 29.99]; const formatted = prices.map(price => `¥${price.toFixed(2)}`); // ['¥19.99', '¥29.99'] // 日期格式转换 const dates = ['2023-01-01']; const formattedDates = dates.map(date => new Date(date).toLocaleDateString()); // ['1/1/2023']
链式操作
// 筛选偶数→乘以3→格式化 const result = [1,2,3,4] .filter(num => num % 2 === 0) .map(num => num * 3) .map(num => `数值: ${num}`); // ['数值: 6', '数值: 12']
与forEach()的对比
| 特性 | map() | forEach() |
| 返回值 |
新数组 |
undefined |
| 用途 |
数据转换 |
执行副作用操作 |
| 链式调用 |
支持 |
不支持 |
| 中断遍历 |
不可用 |
不可用 |
最佳实践:
- 需要新数组时用
map()
- 仅需遍历操作时用
forEach()
手动实现原理
for循环实现
function customMap(array, callback) { const result = []; for (let i = 0; i < array.length; i++) { result.push(callback(array[i], i, array)); } return result; }
for...of循环实现
function customMap(array, callback) { const result = []; let index = 0; for (const item of array) { result.push(callback(item, index, array)); index++; } return result; }
注意事项
- 避免副作用:
map()应返回新值,仅打印或修改外部变量时改用forEach()
- 性能考虑:对大型数组,
for循环性能优于map()
- 稀疏数组处理:
map()会跳过空位(empty项)