Issue
i like to ask for advise how to let this array [1,2,3,4] to become 12, 23, 34?
this initial is a number 1234, i split them
let sum
sum = String(this.numbers).split("").map(Number);
console.log('numbers set1', sum)
so from here it becomes [1,2,3,4]
how can i join/combine/concat then to become 12, 23, 34 respectively?
thank you very much for Hello World's guidance
thank you
Solution
You can easily achieve the result using split, map, and filter
const num = 1234;
const result = String(num)
.split("")
.map((n, i, src) => (src.length !== i + 1 ? `${n}${src[i + 1]}` : null))
.filter(Boolean)
.map(Number);
console.log(result);
Answered By - decpk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.