0
1

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 1 year has passed since last update.

JavaScriptでアップロードされたファイルの拡張子を取得する

Last updated at Posted at 2022-11-13

ファイルが選択されたら以下のコードを実行します。

const filename = 'foo.jpg';
const pos = filename.lastIndexOf('.');
if (pos === -1) {
    console.log('拡張子がありません');
} else {
    console.log('拡張子がありました');
    console.log('拡張子=>', filename.slice(pos + 1));
};

参考

追記

下にコメントいただいた方法も、ぜひ参考にしてください。

0
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?