Does JavaScript support array or list comprehensions like Python?
You can convert the string to an array of characters and filter out the forbidden characters:
const string = '1234-5';
const forbidden = '-';
const result = Array.from(string)
.filter(i => !forbidden.includes(i))
.map(Number);
console.log(result); // Output: [1, 2, 3, 4, 5]
You can split the string on the forbidden character and then reduce the resulting array to individual integers.
const string = '1234-5';
const forbidden = '-';
const result = string.split(forbidden)
.reduce((acc, part) => {
return acc.concat(Array.from(part).map(Number));
}, []);
console.log(result); //
Output: [1, 2, 3, 4, 5]