Hello friends I have the following arrangement
datos = ["1,andres", "2, julian", "3,juan", "12,carlos"]
I want to get the numbers of each element.
I have this but I think I need the index of the comma to be able to tell the substr to remove me from the position given by the , I will use indexof
datos.map(element => {
console.log(element.substr(0, 2));
})
You can do it with the function
split
and use the comma as a separator, then take whatever is at position 0 which is the index:There are several ways to do it. I leave here the variant of the regex: