我目前正在学习 JavaScript 并且我在数组中的对象上度过了一段可怕的时光。
我正在努力寻找他们。它不会找到。
我正在尝试显示它们,它们显示不正确。
我一直在努力解决这个问题大约 2 天,但我迷路了
这是代码
const notes = [{
title: 'The big trip',
body: ' The next big trip will be back to thailand'
},
{
title: 'Fitness goals',
body: 'really enjoying the ab programme '
},
{
title: 'life decisions',
body: 'the move overseas '
}
]
console.log(notes.length)
const findNote = function(notes, noteTitle) {
const index = notes.findIndex(function(note, index) {
return note.title === noteTitle
})
return notes[index]
}
const note = findNote(notes, 'Fitness Goals')
console.log(notes)Run Code Online (Sandbox Code Playgroud)
小智 5
你的代码没问题。请在此处检查您的函数参数:
const note = findNote(notes, 'Fitness Goals')
Run Code Online (Sandbox Code Playgroud)
没有与标题“健身任何音符摹oals”。将此字符串更改为:
const note = findNote(notes, 'Fitness goals')
Run Code Online (Sandbox Code Playgroud)
'Goals'和'goals'在 Javascript 中是不同的字符串,所以程序找不到任何注释
| 归档时间: |
|
| 查看次数: |
49 次 |
| 最近记录: |