Here i will discuss to add a function in string object using prototype, so can access every where in application.
As we know that prototype is super object in javascript.
String.prototype.checkExist = function (charStr) { const str = this.valueOf(); let exitsCheck = false; const strArr = charStr.split(''); for (let i = 0; i < strArr.length; i++) { if (str.includes(strArr[i])) { exitsCheck = true; break; } } return exitsCheck; }
In above function checkExist function will check that a character exist in a string or not,if exists the return true other wise return false.
Reference: https://jsfiddle.net/u6BER/
Top comments (0)