Having recently started coding, I encountered my first issue that I can't seem to solve.
The problem is with a string "XX|Y1234$ZT|QW4567"
where I need to remove both $
and |
, then push the elements into an array like this: ['XX', 'Y1234', 'ZT', 'QW4567']
.
I attempted using the methods .replace
and .split
in many different ways.
var str = "XX|Y1234$ZT|QW4567";
var arr = [];
str = str.split("$");
for(i = 0; i < str.length; i++) {
var tempArr = str[i].split("|");
arr.push(tempArr);
}
I have tried multiple approaches but listing them all would take quite some time.