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?

  • What is your language? - Suvitruf
  • Is the letter always the same? Can a letter be different? Use instead of Split - Left . but in general - you need to show different variants of variables, explain how they can be. - vikttur
  • Language Code - JavaScript - Basilissy
  • In the first place is always any letter of the letter, then - any number, at least 99999999 - Basilius

2 answers 2

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); 

  • What if А is Russian: P - Suvitruf
  • Absolutely any letter, I wrote - Basilius

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));