There is a variable a, equal to 'A13', how to divide it by the letter A and the number 13 to make var b = ['A', '13']
What should be inserted into split as a separator?
There is a variable a, equal to 'A13', how to divide it by the letter A and the number 13 to make var b = ['A', '13']
What should be inserted into split as a separator?
You can use a regular expression:
let a = 'A13'; let r = a.match(/(\D+)(\d+)/i); r.shift(); console.log(r); If there is only one letter, you can somehow:
let a = 'A13'; let r = a.split(''); // в массив букв r = [r.shift(), r.join('')]; // первая и остальные console.log(r); А is Russian: P - Suvitruf ♦If the letter in front of the number is always the same, then split() is not needed in general:
const str = 'А1234567890'; let result = [str.charAt(0), +str.slice(1)]; console.log(JSON.stringify(result)); Source: https://ru.stackoverflow.com/questions/826900/
All Articles