香草Javascript数组对象

时间:2019-01-23 22:25:29

标签: javascript arrays

这是我的代码:

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

const findNote = function (notes, noteTitle) {
  return notes.find(function(note, index) {
    return note.title === noteTitle
  })
}

const filteredNotes = notes.filter(function (note, index) {
  const isTitleMatch = note.title.toLocaleLowerCase().includes('o')
  const isBodyMatch = note.body.toLocaleLowerCase().includes('ne')
  return isTitleMatch || isBodyMatch
})
console.log(filteredNotes)

在控制台中运行它时,出现错误: TypeError:无法读取未定义的属性“ toLowerCase”

当我可以使用.toLowerCase()时,出现错误: const isTitleMatch = note.title.includes('ne')                                   ^

TypeError:无法读取未定义的属性“ includes”

我做错了什么,对Javascript来说我才刚刚接触大约2周。

0 个答案:

没有答案