Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if JavaScript object is a FormData instance

Tags:

I was looking for a way to check if an object is a FormData instance, similarly to Array.isArray()

Edit: If someone knows about instanceof, they obviously won't need to be pointed to instanceof. Obviously not a duplicate.

like image 287
km6 Avatar asked Sep 11 '17 00:09

km6


1 Answers

Use instanceof

For example:

let formData = new FormData()
let time = new Date()

console.log("statement: formData is a FormData instance", formData instanceof FormData) // statement is true
console.log("statement: time is a FormData instance", time instanceof FormData) // statment is false

Source

like image 155
km6 Avatar answered Sep 28 '22 09:09

km6