Monday 12 June 2017

Node.js and Express, data.push is not a function

I'm getting an error pushing newTask to allTasks, with the error being TypeError: allTasks.push is not a function

data is the JSON data pulled from a file using fs

var allTasks = JSON.parse(data);
var newTask = {
    id: Date.now(),
    title: "BAM",
    description: "BOOM",
    image: "SLAM"
};
allTasks.push(newTask);

I've tried declaring allTasks as an array before parsing JSON But that didn't work either.



via Ibrahim Abouhashish

No comments:

Post a Comment