Hey you programmer, okay? What about learning something new?
Our focus here is to transform a string into an array
Either because we want to create this set or also when we get some text from the backend, for example, and we want to turn it into an array
| Do you want to specialize in Web Development? Check out our course catalogue.
Native methods are the functions that come within the language, that is, ready to use
See the example:
const texto = "Temos uma string aqui"; const array = texto.split(" "); console.log(array); // ["Temos", "uma", "string", "aqui"];
Using the split method on a string, we get an array back
It is important to remember that the split parameter must be the array separator
By comma, space, dash, in short, the way we want the string to be separated
So it will be split every time split finds the parameter in the string, generating the array
For this we use the join method, we must assign it to a variable and use it in the string
And the parameter passed is the array separator, for example: if we pass a comma the string will be separated into an array for each comma found