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....

6
  • Let me introduce you to the for loop... Commented Jun 22, 2016 at 10:18
  • do you want to change value "31/05/2015 00:00:00" to "31/05/2015" Commented Jun 22, 2016 at 10:18
  • 2
    ["data": is not valid in javascript, it will trow Uncaught SyntaxError: Unexpected token : Commented Jun 22, 2016 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 Commented Jun 22, 2016 at 10:21
  • iterate over the inner array and update object property.... for updating split string using space and get string at index 0 Commented Jun 22, 2016 at 10:22

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.