複数の選択肢のうちの少なくとも一つ。 ..if文==私は私が取得しようとしていますどのようなものを例を持って<code>x == (at least one of many vars)</code></p> <p>かどうかを確認するif文の書き方の適切な構文を把握しようとしています
var path = require('path')
var fs = require('fs')
var file1 = './frank.txt'
var file2 = './jasmine.html'
var file3 = './finnigan.jpg'
if (fs.statSync(file2).isFile && path.extname(file2) == ['.txt' || '.html']) {
console.log('true')
} else {
console.log('failure')
}
私は後の構文は& &ある知っては奇妙ですが、状況の正しい構文は何ですか?
のような正規表現を使用することができます。最初は '(path.extname(file2)== '.txt' || path.extname(file2)== '.html')'ですが、それは明白な理由から悪いことです。 '['.txt'、 '.html']。indexOf(path.extname(file2))> -1'が動作します。同様に 'path.extname(file2).match(/ \。(?: txt | html)$ /)' ... –
をチェックする[this](http://stackoverflow.com/questions/25171143/how-do -i-use-the-method-in-method-in-object-in-the-colleを含む)を使用して、この種の作業を容易にするためにlodashモジュールを使用します。 – n0m4d