Switch statement for string matching in JavaScript

前端 未结 9 1490
深忆病人
深忆病人 2020-11-29 15:46

How do I write a swtich for the following conditional?

If the url contains \"foo\", then settings.base_url is \"bar\".

The following is achi

9条回答
  •  再見小時候
    2020-11-29 16:22

    You could also make use of the default case like this:

        switch (name) {
            case 't':
                return filter.getType();
            case 'c':
                return (filter.getCategory());
            default:
                if (name.startsWith('f-')) {
                    return filter.getFeatures({type: name})
                }
        }
    

提交回复
热议问题