Nodejs String Contains contains()

Here you can find the source of contains()

Method Source Code

var fs = require('fs');

var path = process.argv[2];
var suffix = '.'+process.argv[3];

var list =[];/*from  w ww .  j  a v a  2 s  .c  o m*/

String.prototype.contains = function() {
    return String.prototype.indexOf.apply( this, arguments ) !== -1;
};

fs.readdir(path, function(err, files){
  if(!err){
    for (var i = 0; i < files.length; i++) {
      if (files[i].contains(suffix)) {
        list.push(files[i]);
      }
    };
  }
  for (var i = 0; i < list.length; i++) {
    console.log(list[i]);
  };
});

Related

  1. Contains( str )
    String.prototype.Contains = function( str )
        return this.indexOf( str ) > -1;
    };
    
  2. Contains( textToCheck )
    String.prototype.Contains = function( textToCheck )
      return ( this.indexOf( textToCheck ) > -1 ) ;
    
  3. containIgnoreCase(otherStr)
    String.prototype.containIgnoreCase = function (otherStr) {
        return this.toLowerCase().indexOf(otherStr.toLowerCase());
    
  4. contains( s, index)
    String.prototype.contains  = function( s, index) {
      return this.indexOf(s,index||0) > -1;
    
  5. contains()
    String.prototype.contains = function() {
      var args = arguments;
      for (var i in args) {
        var str = args[i];
        if (typeof str === "string" && this.indexOf(str) > -1) {
          return true;
      return false;
    ...
    
  6. contains()
    String.prototype.contains = function () {
      return String.prototype.indexOf.apply(this, arguments) !== -1;
    };
    
  7. contains(a)
    String.prototype.contains = function (a) {
      if (this.indexOf(a) > -1)
        return true;
      else
        return false;
    };
    
  8. contains(argument)
    var string = "Hello world, my name is cole hudson. This is super cool.";
    String.prototype.contains = function(argument){
      var parent = this.toLowerCase();
      var argumentString = argument.toLowerCase();
      return (parent.indexOf(argumentString) > -1);
    };
    console.log(string.contains("World"));
    
  9. contains(char)
    String.prototype.contains = function(char) {
        return this.indexOf(char) != -1;
    };