string - Jquery check if both values are starting with same text -


i jquery how check 2 values starting same texts,

my code is

$a = "hello john"; $b = "hello peter"; 

$a == $b --> false

like how find variables staring string.

approach 1

click here demo

if (!string.prototype.startswith) {     object.defineproperty(string.prototype, 'startswith', {         enumerable: false,         configurable: false,         writable: false,         value: function (searchstring, position) {             position = position || 0;              return this.indexof(searchstring, position) === position;         }     }); }   var str = "pankaj garg";  alert(str.startswith("pankaj"));   // true alert(str.startswith("garg"));     // false alert(str.startswith("garg", 7));  // true 

if pay attention third alert, can start comparison after leaving chars also


approach 2

click here demo

if (typeof string.prototype.startswith != 'function') {       string.prototype.startswith = function (str){           return this.indexof(str) == 0;   }; }  var data = "hello world"; var input = 'he'; if(data.startswith(input)) {     alert("ok"); } else {     alert("not ok"); } 

approach 3

check here demo

var str = "hello a"; var str1 = "hello b"; if(str.match("^hello") && str1.match("^hello"))  {     alert('ok'); } else {     alert('not ok'); } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -