I'm taking a course on udemy and i'm really confused on how notes = JSON.parse(notesString) is an array when it's suppose to be an object (right?) since JSON.parse makes it an object.
var addNote = (title, body) => {
var notes = []; // Create empty array
var note = { // Fetch user input
title,
body
};
try {
var notesString = fs.readFileSync("notes-data.json"); // Get current notes
notes = JSON.parse(notesString); // convert current notes into object
console.log("try:", notes.constructor)
}catch(e){
}
console.log(notes)
notes.push(note);
fs.writeFileSync("notes-data.json", JSON.stringify(notes));
};
var notes = []; // Create empty arrayJSON.parsereturns the value of the same type it was initially.