I have a variable that calls all people names.
var nome = "João Miguel Pedro";
How do I make it to become the following array:
var nome1 = ["João","Miguel","Pedro"];
I have a variable that calls all people names.
var nome = "João Miguel Pedro";
How do I make it to become the following array:
var nome1 = ["João","Miguel","Pedro"];
First of all, one option is to use split()
to separate by space. See:
var nome = "João Miguel Pedro"
var nome1 = nome.split(" ");
console.log(nome1);
Or you can do a regex to make a split()
in all capital letters, as you queried in the comments. See:
var nome = "JoãoMiguelPedro"
var nome1 = nome.split(/(?=[A-Z])/);
console.log(nome1);