Consider the following JSON data object:
var dataObjects = [
{
"Name": "Date & Time",
"Type": "Date",
"Value": "2019-12-11"
},
{
"Name": "Activity",
"Type": "String",
"Value": "ADD"
}
]
I am looking to create a new JSON data array object based on the existing one, but with the date formatted differently from "2019-12-11" to "December 11, 2019".
I have attempted to achieve this by consulting various resources online, however, I keep encountering syntax errors in my code.
My understanding of Typescript and Javascript is limited, which is why I am seeking assistance as even seemingly simple tasks prove to be challenging for me. Your help is much appreciated.
public FunctionA(dataObjects: any[]): object
{
let returnObj: any = {}
let returnObjArray: any = [];
for(let obj in dataObjects){
var dateValue = obj.Date;
if(obj.Type == "Date"){
dateValue = obj.Date.Format()
}
returnObj = {"Name", obj.Name, "Type": obj.Type, "Value": dateValue };
returnObjArray.push(returnObj);
}
return returnObjArray;
}
I recognize that the issue lies in specifying the type of the "any" array before using its properties. Despite attempting to declare it below, I continue to face errors:
dataObjects: Array[{ Name: string, Type: string, Value: string }]