I need to return an empty array if obj.chk != true to check if no checked toDos
function listChk()
{
if (!chkExist('./toDoArr')) {console.log('Please create toDo list first!')}
else {
let toDoArr = JSON.parse(fs.readFileSync('./toDoArr'))
let chkToDoArr = toDoArr.map(function (obj) {
if (obj.chk === true){
console.log( obj.toDo)
return obj.toDo
}
});
console.log(chkToDoArr) // >> [ undefined, undefined ]
if (chkToDoArr.length < 1)
console.log('no checked toDos or empty list');
}
}
thanks
.map()is if your input is an empty array. You have to re-think how you approach this, since you cannot embed the logic in the mapping function.