Sometimes, we want to detect if JavaScript object is a FormData
instance.
In this article, we’ll look at how to detect if JavaScript object is a FormData
instance.
How to detect if JavaScript object is a FormData instance?
To detect if JavaScript object is a FormData
instance, we can use the instanceof
operator.
For instance, we write:
const formData = new FormData()
console.log(formData instanceof FormData)
to create a new FormData
instance and assign it to formData
.
Next, we check if formData
is an instance of FormData
with the instanceof
operator.
The console log should log true
since formData
is a FormData
instance.
Conclusion
To detect if JavaScript object is a FormData
instance, we can use the instanceof
operator.