List all states in the JS and Mongo Node

1

I'm trying to assemble a function to list all states and then print inside an object. Sorry to be so noob, I think it's a pretty silly problem.

States

    function listarTodasOsEstados(){
    var estado = [
        'AC',
'AL',
'AP',
'AM',
'BA',
'CE',
'DF',
'ES',
'GO',
'MA',
'MT',
'MS',
'MG',
'PA',
'PB',
'PR',
'PE',
'PI',
'RJ',
'RN',
'RS',
'RO',
'RR',
'SC',
'SP',
'SE',
'TO'
        ]

var mostrar_para_o_painel = console.log(estado);
return mostrar_para_o_painel;
};

Context:

User.add({
estado: { Types.Select, options: listarTodasOsEstados(), label:"Estado", initial:true} })

Result:

/home/pedromagalhaes/Projects/Projeto_Ag2/node_modules/keystone/fields/types/select/SelectType.js:21
        throw new Error('Select fields require an options array.');
        ^
    
asked by anonymous 28.10.2017 / 20:30

1 answer

2

The problem is that your function is returning undefined . This happens because your function returns a variable that is the result of console.log() .

There is no need to create a new variable in the penultimate row of the function ( mostrar_para_o_painel ). Just change the finasi lines to

console.log(estado);
return estado;
    
28.10.2017 / 20:54