Javascript,Lodash,Underscore更改Array的值

时间:2016-06-22 10:15:36

标签: javascript arrays underscore.js lodash text-parsing

可能是重复的,但在这里读了很多关于如何实现以下内容并且无法完全按照我的需要进行操作。阅读:Javascript array Link2 link3

我有一个大型数组(下面提供的简短示例),并希望格式化REPORT_DATE值,而不是例如" 31/05/2015 00:00:00"我得到31/05/2015。有谁知道一个简单的方法吗?

{["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

感谢帮助......

1 个答案:

答案 0 :(得分:1)

你粘贴了一个格式错误的代码片段,顺便说一下,你可以使用`Array.prototype.map'修改一个数组。如果您不需要内存参考



"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)