命令提示符给出错误" notes.filter不是函数"

时间:2018-06-05 21:48:45

标签: javascript

var getNotes=()=>{
    try{
        var notestring=fs.readFileSync("notes-data.json");
        return JSON.parse(notestring);
    }
    catch(e){
    }   
}
var saveNotes=(notes)=>{
    fs.writeFileSync("notes-data.json",JSON.stringify(notes));
}
var addNotes=(title,body)=>{
    var notes=getNotes();
    var note={
        title,
        body
    }
            if(typeof(notes)==="undefined")
            {
                notes=note;
                saveNotes(notes);
                return note;
            }
            else
            {
                console.log("notes are");
                console.log(notes);
                var duplicate=notes.filter((note) => title===note.title);
                if(duplicate.length===0)
                {
                    notes.push(note);
                    saveNotes(notes);
                    return note;
                    // if not returned anything javscript return undefined 
                }   
            }
}

当在notes数组上调用过滤器函数时,它会给出错误,但是为什么我在添加包含标题和正文的注释之前使用过滤器函数检查是否有任何重复的标题,然后再添加到json文件

0 个答案:

没有答案