So i am wondering how i can remove the space of last element in array.
Let's say i have a string:
let str = "d d, b b, c c, d d ";
let split = str.split(", ");
let arr = split.map(str => str.replace(/\s/g, '_'));
console.log(arr);
So as you can see i am chaining words inside array, but i have a problem that my last item in array have whitespace at the end which end with "_" at the end. How i can remove that space from the last element without removing the space between d d?
let arr = "d d, b b, c c, d d ".trim().replace(/ /g,"_").split(",");