Categories
JavaScript Answers

How to detect if JavaScript object is a FormData instance?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *