0
0

More than 1 year has passed since last update.

IN演算子 JavaScript

Posted at

用途

  • オブジェクトに存在するかどうかを調べる
  • 配列に対して要素番号が存在するかどうか調べる

使用方法

オブジェクトに存在するかどうかを調べる

var hoge = {
a : "aです"
}
console.log("aです" in obj); //true
console.log("bです" in obj); //false

文言 in 値 というように記述すると、文言 に存在している場合は true が、存在しない場合は false が返ってくる。

配列に対して要素番号が存在するかどうか調べる

var hoge = ["a", "b", "c"];
console.log(0 in hoge); //true
console.log(1 in hoge); //true
console.log(2 in hoge); //true
console.log(3 in hoge); //false

 
 
この記事は以下の情報を参考にして執筆しました。

0
0
0

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
0
0