I am writing a CLI application using JS and inquirer
. From the following code, I expect to get some console.log() from both of the for loops. However, there is no console.log even if checkChoices
and answers
both have values inside of them.
JS
view(){
let checkChoices = [];
for(let i = 0; i < this.list.length; i++){
checkChoices.push(this.list[i].text);
}
let viewList = [
{
type: 'checkbox',
name: 'command',
message: 'Your Checklist',
choices: checkChoices
}
]
console.log(checkChoices.length);
inquirer.prompt(viewList).then((answers) => {
for(let i = 0; i < answers.length; i++){
let answer = answers[i];
console.log("answer", answer)
for(let j = 0; j < checkChoices.length; j++){
console.log("choice", checkChoices[j])
if(answer == checkChoices[j]){
this.list[j].complete = true;
}
}
}
console.log(this.list);
// this.ask();
})
}
};
Via the comments, it was discovered that answers
was an object, rather than an array. Objects do not, inheriently, have a length
property.
As the object had a single property of command
with a value of an array, the assumption is that the logic should loop over answers.command
, rather than trying to loop on the answers object.