There are two components to solving this issue - referencing the item with an empty name, and renaming it.
To reference any property, even with special characters or in this case an empty string, you can specify the property name as a string in square brackets like so:
data["my property with spaces"]
data[""]
Now that we can reference the empty property name, we now need to rename it. This can be achieved by deleting the original property and creating a new one with the same value. You can delete the property with the delete
keyword, as follows
delete data[""]
Here is the complete final answer, which stores the value in a temporary variable, deletes the property you don't want, and assigns the stored value to a new different property name:
const data = {
"success": true,
"data": [
{
"": "abc123abc"
}
]
}
const dataObjectToModify = data.data[0]
const originalPropertyValue = dataObjectToModify[""]
delete dataObjectToModify[""]
dataObjectToModify["application_num"] = originalPropertyValue