I have a function wherein I want to do some things with a class object selected by the user. I was thinking, I present them with some options, then after they select it, I use the string to identify the class object in an array of objects like so:
function askAboutIt() {
var questions = [{
type: 'list',
name: 'theList',
message: "Message",
choices: listArray
}]
inquirer.prompt(questions).then(answers => {
var itemInQuestion = (answers['theList']);
function isPicked(item) {
return item.name === itemInQuestion;
}
var picked = (listArray.find(isPicked));
})
}
Basically inside of some other function I would like to be able to call askAboutIt()
and have it return picked
. That way I could, for example, console.log(askAboutIt()),
or maybe create a variable equal to askAboutIt().someOtherPropertyofmyListArrayClass.
I tried sticking a return
in my inquirer function, but it returns as undefined, so then I thought, maybe I could stick an await
outside of my console.log
, but that's not getting the return either.
So then I tried using the when
method from this answer, but then I got returned an error that "when is an unexpected identifier." Where exactly am I supposed to put the when
method, or should I use something else entirely?