gpt4 book ai didi

JavaScript - 无法读取未定义的属性 'toLowerCase'

转载 作者:行者123 更新时间:2023-11-30 11:12:10 24 4
gpt4 key购买 nike

找不到问题,但是一直显示这个错误!!使用 includes 等其他方法时也会发生同样的情况。

let notes = [{},{
title: 'My next trip',
body: 'I would like to go to Spain'
},{
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
},{
title: 'Office modification',
body: 'Get a new seat'
}]

let filteredNotes = notes.filter( function (note, index) {
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')

return findFileredTitle || findFileredBody
})
console.log(filteredNotes)

最佳答案

您的数组 notes 包含四个元素。第一个是空的。看到一对空牙套了吗?

let notes = [{}, {

当您稍后访问它时:

note.title.toLowerCase() === ...

然后 note.title 未定义,您会收到错误消息。

很可能,您想远程控制一对空括号。

关于JavaScript - 无法读取未定义的属性 'toLowerCase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53250442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com