2015-07-21 50 views
0

我的日期轉換爲使用Date.parse()時間戳。每次我找到鑰匙「Date__c」的值。使用lodash /強調我怎麼可以更新的關鍵

[ 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    } 
] 

To become 


[ 
    { 
     "Date__c":1438185600000, 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":1438185600000, 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":1438185600000, 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    } 
] 

回答

0
arr = [ 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    }, 
    { 
     "Date__c":"07/30/2015", 
     "End_Time__c":"14:00", 
     "Start_Time__c":"07:00" 
    } 
] 

_.map(arr, 
    function (a) { 
     return _.mapValues(a, function(v, k) { 
       return "Date__c" == k ? new Date(v).valueOf() : v; 
      } 
     ) 
    } 
)