I have a variable called jobs in my scope, which is an array containing objects for each department along with their respective data.
[ “Accounting”: { “foo” : “foo”, “bar” : "bar" }, “Delivery”: { “foo”: “foo”, “bar”: “bar” } ]
When using the HTML5 date input, dates must be converted to new Date() format in JavaScript, even if they are already in the correct yyyy-mm-dd format. Instead of manually converting each date, I wanted to use nested loops to do it efficiently since there are multiple dates to convert.
angular.forEach($scope.job, function(value, key){
angular.forEach(value, function(innerValue, innerKey){
if(typeof(innerValue) === "string"){
var matches = innerValue.match(/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/);
if(matches){
// Need to set $scope.job.key.innerKey = new Date($scope.job.key.innerKey) here
}
}
});
});
The challenge I’m facing is figuring out how to access and edit the current item being looped over within the $scope.job object at specific key and innerKey values. I couldn’t find much documentation on using ‘this’ in such scenarios.