1

May be a duplicate but read alot on here on how to achieve the following and couldn't get it to do exactly what I need. Read: Javascript array Link2 link3

I have a large array (short sample provided below) and would like to format the REPORT_DATE value so that instead of for example "31/05/2015 00:00:00" I get 31/05/2015. Does anyone know of an easy way to do this ?

{["data":[{"DOC1":"1234","FILE_NAME":"4321.PDF","TITLE":"gwewrgw","REPORT_DATE":"31/05/2015 00:00:00","CLIENT_ID":"1234512","CLIENT_NAME":"Zuba"}
     ,{"DOC1":"4737","FILE_NAME":"52345.PDF","TITLE":"erywery","REPORT_DATE":"30/09/2015 00:00:00","CLIENT_ID":"5234523","CLIENT_NAME":"Ziba"}
     ,{"DOC1":"1234","FILE_NAME":"452345.PDF","TITLE":"wgrwrg","REPORT_DATE":"31/05/2015 00:00:00","CLIENT_ID":"23452345","CLIENT_NAME":"Zuba"}
     ,{"DOC1":"4737","FILE_NAME":"2345234.PDF","TITLE":"wegwerg","REPORT_DATE":"30/09/2015 00:00:00","CLIENT_ID":"4523452","CLIENT_NAME":"Ziba"}
     ,{"DOC1":"4737","FILE_NAME":"52342345.PDF","TITLE":"egwergw","REPORT_DATE":"30/09/2015 00:00:00","CLIENT_ID":"43532452","CLIENT_NAME":"Ziba"}],"pagination":{"ItemsPerPage":"5","IntervalFrom":"1","IntervalTo":"5","TotalPages":"14","TotalItems":"68","CurrentPage":"1","pageSizes":[{"name":"5","items":5},{"name":"10","items":10},{"name":"25","items":25},{"name":"50","items":50},{"name":"100","items":100}],"maxSize":5}}

[image

Appreciate the help....

Community
  • 1
  • 1
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
  • Let me introduce you to the [`for` loop](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for)... – Niet the Dark Absol Jun 22 '16 at 10:18
  • do you want to change value `"31/05/2015 00:00:00" ` to `"31/05/2015"` – Pranav C Balan Jun 22 '16 at 10:18
  • 2
    `["data":` is not valid in javascript, it will trow _`Uncaught SyntaxError: Unexpected token :`_ – Pranav C Balan Jun 22 '16 at 10:20
  • I am trying to learn a better way than a regular for loop since I am sure thiss is a 1-2 line thing with lodash and underscore but I can't seem to do it. @Pranav trying to format the "REPORT_DATE" value so that the " 00:00:00 doesn't appear – Afshin Ghazi Jun 22 '16 at 10:21
  • iterate over the inner array and update object property.... for updating split string using space and get string at index 0 – Pranav C Balan Jun 22 '16 at 10:22
  • thanks for the help, but updated question to display object I am getting back from console.log – Afshin Ghazi Jun 22 '16 at 10:25

1 Answers1

1

you pasted a bad-formatted snippet, by the way, you can modify an array using `Array.prototype.map' if you don't need for the memory reference

"use strict";

var data = [{"DOC1":"1234","FILE_NAME":"4321.PDF","TITLE":"gwewrgw","REPORT_DATE":"31/05/2015 00:00:00","CLIENT_ID":"1234512","CLIENT_NAME":"Zuba"}];

var result = data.map(i => {
  i.REPORT_DATE = Date.apply(null, i.REPORT_DATE.split(' ').reverse());
  
  return i;
});

console.log(result)
Hitmands
  • 13,491
  • 4
  • 34
  • 69