JavaScript:TypeError无法读取未定义的属性“ toLowerCase”?

时间:2018-08-23 04:57:53

标签: javascript arrays typescript web

运行此代码时出现错误,是说typeerror无法将属性读取为未定义的“小写字母”。 代码:-

const notes = [{},{
    title: "My next Trip",
    body: "I would like to go to USA"
},{
    title: "Habbits to work on",
    body: "Exercise"
} ,{
    title: "Office Modification",
    body: "Get a new seat"
} ]

 const findNote = function(notes, noteTitle) {
     const index = notes.findIndex(function (note , index) {
         return note.title.toLowercase() ===  noteTitle.toLowerCase()
     })
     return notes[index]
 }
const note = findNote(notes, "Office Modification")
console.log(note);

1 个答案:

答案 0 :(得分:1)

代码中有2个错误

  • JavaScript区分大小写-正确的功能是library(ggplot2) library(scales) library(rlang) # for sym myfunction <- function(var1,var2){ p <- ggplot(diamonds, aes(x=cut, y= !! sym(var1)) ) + geom_boxplot() + scale_y_continuous(labels = get(var2)) p return(p) } myfunction('price','dollar')
  • 有一个没有toLowerCase属性的空对象-您需要在代码中为此添加安全检查

您可以尝试关注

title