1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

phpとjsの配列の型判定の違い

Posted at

phpの配列の判定

gettypeを使えば簡単に判定できる

$array1 = [1,2,3];
echo gettype($array1); // array

jsの配列の判定

間違い. typeofを使うと判定はできるが、配列がオブジェクトになってしまう

let array2 = [1,2,3];
console.log(typeof this.array2); // Object

正解. instanceofを使って、正誤を判定する


let array3 = [1,2,3];
console.log(this.array3 instanceof Array); // true

何か間違いやアドバイスがあれば教えてもらえると幸いです。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?