why javascript contains property is not working in chrome browser?

前端 未结 6 1300
孤城傲影
孤城傲影 2021-02-01 15:39

Why javascript contains property is not working in chrome browser? I have tried that Contains Property in javascript.It is working fine in Mozila Firefox Browser. But It is

6条回答
  •  一生所求
    2021-02-01 16:15

    contains is not supported in Chrome, but you could use a polyfill:

    if (!String.prototype.contains) {
        String.prototype.contains = function(s) {
            return this.indexOf(s) > -1
        }
    }
    'potato'.contains('tat') // true
    'potato'.contains('tot') // false
    

提交回复
热议问题