ms_nitrogen ms_nitrogen - 1 year ago 81
Javascript Question

if statement == at least one of multiple options

I am trying to figure out the proper syntax of how to write an if statement that checks if

x == (at least one of many vars)

I have an example what what I am trying to get to...

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']) {
} else {

I know the syntax on the after is && is weird, but what is the correct syntax for the situation?

Answer Source

You can check if a certain index exists by the elment:

if (fs.statSync(file2).isFile && ['.txt', '.html'].indexOf(path.extname(file2)) > -1) {
else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download