Here I have a line of code which I would prefer to take '123' as a string value.
Then with the help of split() and join() it will become a string like '1,2,3'.
Then I want to replace all the numeric string values with actual number like 1,2.....
For this I used a variable called k and give it an initial value 1.
I used an increment operator inside replace to change the value of k.
But it is not working. Maybe I am getting it wrong how string.replace() execute the replacement operation.
I also tried to use parseInt('$1') it also didn't work.
console gives output of 1,1,1.No increment operation takes place.
<html>
<body>
<script>
(function(){
var k=1;
console.log(prompt('input here').split('').join(',').replace(/(\d)/g,k++));
})();
</script>
</body>
</html>
"123"into an array of numbers[1, 2, 3]?var arr = '123'.split('').map(Number);is the simplest solution I know.var a = "123".split('').map(function(item) { item = parseInt(item, 10); return ++item; });works for me