I have a large array of strings in the format PRODUCTCODE1-QTY,PRODUCTCODE2-QTY,...,PRODUCTCODEN-QTY
I need to replace all the product codes with new product code retaining the existing QTY with the high optimised fastest code.
The expected result is
"1234-2,1234-2"
""
""
""
"1234-2"
"1234-2,1234-2"
"1234-4"
"1234-4,1234-4"
The given strings are
"22543-2,25543-2"
""
""
""
"2543-2"
"2543-2,2543-2"
"2543-4"
"25543-4,25743-4"
I have tried with
var strings = str.split(",")
for(i=0;i<strings.length;i++)
{
var q = '';
var qty = string.split("-")[1]
result.push("1234-"+qty)
}
r = result.join(",")
"1234-2,1234-2". Shouldn't it be"1234-4"then? Seeing that you just have two lines with the same product code?