List all states in Node JS and Mongo

Asked

Viewed 82 times

1

I’m trying to set up a function to list all the 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} })

Upshot:

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

1 answer

2


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

No need to create a new variable in the penultimate line of the function (mostrar_para_o_painel). Just switch the final lines to

console.log(estado);
return estado;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.