如何获得 Inquirer 选择的索引值?

问题描述

当被问到这个问题时,我试图从用户那里得到一个整数值:

        let q4 = {
        type: 'list',name: 'manager',message: 'Who do they report to?',choices: ['Jen','Rachel','Tania']
    };

let answerProcessing = (answer) => {
     console.log(answer.manager)
            }

但我无法从文档中弄清楚,并且我没有看到与此类似的任何问题。也许这真的很明显,但我无法得到非字符串响应。

解决方法

想通了:

console.log(q4.choices.indexOf(answer.role));

这将给出索引值。 放弃它,因为我看不到其他类似的问题。