I have this code to pass a string to an array
let str = 'Los desarrolladores de nik son [pepe] y [pepito]';
let arr = str.split(' ');
console.log(arr);
This as a result gives me an array that contains each word, does anyone know how to make [pepe] and [pepito] remain inside the array with empty brackets
that instead of this:
['Los', 'desarrolladores', 'de', 'plop', 'son', '[pepe]', 'y', '[pepito]']
left this:
['Los', 'desarrolladores', 'de', 'plop', 'son', '[]', 'y', '[]']
You can do this by substituting (with
string.replace
and a regex) the names in the square brackets for empty square brackets. After thearray.split
. Something like: