While I have seen a similar question before, I am still unsure how to apply the solution in my specific case.
I am working with a function that returns a stringified JSON object, but I need to modify one of the keys using a parameter within the function. Here is an attempt I made to replace it with the parameter value:
function toJSON(... name: string, timestamp: number, x :number, y: number ...): string {
return JSON.stringify({
...
`${name}`: [
{
timestamp: timestamp,
x: x,
y: y
}
]
...
})
Is there a straightforward way to simply substitute this key with a parameter?
In this context, the ...
serves as a placeholder for additional content both before and after.