1

Hi I am looking for a way to transform my data to change the unix time stamp to DD/MM/YYY in given response format and return the same format back, I tried many ways to but I couldn't achieve what I wanted.

Here is the response format.

const mockResponse = 
  { identifier : 'something'
  , palette    : 'sev'
  , fus_config : 
    { dataSource: 
      { chart: { } 
      , dataset: 
        { data: 
          [ [ '1631212200000', 4.85, 27.49, 25] 
          , [ '1631212200000', 4.07, 25.39, 37] 
          , [ '1631212200000', 4.66, 24.48, 56] 
          , [ '1631212200000', 4.77, 24.05, 45] 
          ] 
  } } } } 

I am expecting this to be transformed into this.

const mockResponse = 
  { identifier : 'something'
  , palette    : 'sev'
  , fus_config : 
    { dataSource: 
      { chart: { } 
      , dataset: 
        { data: 
          [ [ '12/13/1995', 4.85, 27.49, 25] 
          , [ '12/13/1995', 4.07, 25.39, 37] 
          , [ '12/13/1995', 4.66, 24.48, 56] 
          , [ '12/13/1995', 4.77, 24.05, 45] 
          ] 
  } } } }

Thank you for your help.

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
Gaurav
  • 11
  • 2
  • Do you know how to convert a single value of Unix time? – PM 77-1 Sep 23 '21 at 18:13
  • Yes, Like moment.unix(value).format("MM/DD/YYYY"); – Gaurav Sep 23 '21 at 18:14
  • OK. Do you know how access attributes of a nested object? In your case, how to find the list for `data`? – PM 77-1 Sep 23 '21 at 18:19
  • I tried transforming the unix time stamp to this format format("MM/DD/YYYY"); using forEach but it's adding the index as an item i.e. ['12/13/1995', 4.85, 27.49, 25, "0"], ['12/13/1995', 4.85, 27.49, 25, "1"] – Gaurav Sep 23 '21 at 18:20
  • 1
    Add your code to your question. This will greatly improve your chances for a good answer. Do **not** post code as comments - use [Edit] instead. – PM 77-1 Sep 23 '21 at 18:26

0 Answers0