I have this string in the form of
ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_ItemName3:Rate3:Tax3_ItemName4:Rate4:Tax4 (and so on, upto item 25).
What I have to do is, user will pass a index, (say 2) grab the item at that index, when this string is split by _, for eg. if index is 2, I would get the substring ItemName3:Rate3:Tax3. another thing the user will pass is 3 args, indicating newItem, newRate, and newTax, then I have to replace these old items found at that particular index with these new values and return the new string. Perhaps an example would make it clear
var itemList=ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_ItemName3:Rate3:Tax3_ItemName4:Rate4:Tax4
user passed arguments, 2, Denim Jeans, 399.00, 14.34.
This must replace the original itemList and return
ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_Denim Jeans:399.00:14.34_ItemName4:Rate4:Tax4
(Hope I made myself clear).
I know the simplest way would be first split the itemList by _ and then at given index, split by : and then replace those items, then using a for loop make a new string and then return that new string. But it seems like a lot of work. Isn't there a simple way that this could be achieved by using .each() and/or .map(), though may be inside a for, I won't mind that!