1
I’m blogging to train with Ode. In the application, the user registers in the database and, after logging in, goes to his page, where are all his articles. The field in SQL goes as name
, and I re-address passing to the EJS through a variable user.name
.
<h2>Olá, <span id="trocarNome"><%-user.name%></span></h2>
This code is coming out like this:
Hello, Gustavo Henrique
I wish only the first name came out:
Hello, Gustavo
I would like to make Javascript use the function .split(' ')
, doing so he brings me the name to the first space. But how do I put it into practice?
Have you ever tried something like
const primeiroNome = user.name.split(' ')[0];
and put thisprimeiroNome
in the EJS?– BrunnoFdc
worked out, thanks!!
– guestavo-evaristo