Forum Discussion

Tanmay_Sarkar's avatar
Tanmay_Sarkar
New Contributor III
5 years ago
Solved

Copy a data multiple times in the same array with iteration

Hello All, I stumbled upon a requirement this morning and would like some help/suggestions to work ahead on the solution. I am looking for a way to copy an object inside an array for 36 times while...
  • bojanvelevski's avatar
    5 years ago

    Hello @Tanmay_Sarkar,

    You can use the following expression :

    sl.range(36).map(x=>$.mapValues((value,key) => key == ‘date’ ? Date.parse(value).plusDays(x).toLocaleDateString({“format”:“MM/dd/yyyy”}) : value))

    What it does is the following, the sl.range() function will produce an array of numbers from 0 to 35. On every (x) member of the array, it’s mapping the incoming document, where if the “key” is “date” , increment the date for (x) days, else map the field with no changes.

    Best regards,

    Bojan Velevski