Checks if the specified string is equal to current string - Node.js String

Node.js examples for String:Parse

Description

Checks if the specified string is equal to current string

Demo Code


/**//from  ww  w . ja  v  a 2 s  .  c  om
* Checks if the specified string is equal to current string
*
* @param {String} s
*        A string to be tested
* @return {boolean}
*        <code>true</code> if the specified string is equal to current string
*/
String.prototype.is = function (s) { 
  return (this == s); 
};

String.prototype.isAny = function () {
  var a = arguments, l = a.length, rv = false, aL;
  for (var i=0; i<l && !rv; i++)
  {
    if (typeof(a[i]) == "string")
    {
      rv = (this == a[i]);
    }
    else
    {
      //It's an array (of strings)
      aL = a[i].length;
      for (var j=0; j<aL && !rv; j++)
      {
        rv = (this == a[i][j]);
      }
    }
  }
  return rv;
};

Related Tutorials