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

[TypeScript]変数の中身が配列かどうかを判定する方法

Posted at

TypeScript で変数の中身が配列かどうかを判定する方法を説明していきたいと思います。配列かどうか確認するのに今回は Arrayオブジェクト の isArray 関数を利用します。

isArray 関数の使用方法

実際には以下のように利用します。

const varArr = ['a', 'b', 'c'];
const isArray = Array.isArray(varArr);

console.log(isArray);
// true

このように配列かどうが判定したい変数を isArray 関数の引数に設定することで対象の変数が配列かどうが判定することかできます。

最後に

TypeScript で変数の中身が配列かどうかを判定する方法を説明してきました。変数の方の判定を行うことも多いと思うので、今回の判定方法を有効活用してもらえればと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?