Nodejs String Capitalize capitalize()

Here you can find the source of capitalize()

Method Source Code

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

// attach the .equals method to Array's prototype to call it on any array
Array.prototype.equalTo = function (array) {
    // if the other array is a falsy value, return
    if (!array)//w  w w .  j  av a 2 s .co m
        return false;

    // compare lengths - can save a lot of time
    if (this.length != array.length)
        return false;

    for (var i = 0, l=this.length; i < l; i++) {
        // Check if we have nested arrays
        if (this[i] instanceof Array && array[i] instanceof Array) {
            // recurse into the nested arrays
            if (!this[i].equals(array[i]))
                return false;
        }
        else if (this[i] != array[i]) {
            // Warning - two different object instances will never be equal: {x:20} != {x:20}
            return false;
        }
    }
    return true;
};

Related

  1. capitalize()
    String.prototype.capitalize = function() {
       return this.charAt(0).toUpperCase() + this.slice(1);
    String.prototype.titleize = function() {
       var string_array = this.split(' ');
       string_array = string_array.map(function(str) {
          return str.capitalize();
       });
       return string_array.join(' ');
    ...
    
  2. capitalize()
    String.prototype.capitalize = function(){
      var val = this;
      return val[0].toUpperCase() + val.substring(1);
    
  3. capitalize()
    String.prototype.capitalize = function(){ 
        return this.replace(/\w+/g, function(a){
            return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
        });
    };
    
  4. capitalize()
    String.prototype.capitalize = function() {
      return this.charAt(0).toUpperCase() + this.slice(1);
    };
    $.fn.ensureVisible = function () { $(this).each(function () { $(this)[0].scrollIntoView(); }); };
    
  5. capitalize()
    String.prototype.capitalize = function(){
      return this.replace(/\S+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
      });
    };
    
  6. capitalize()
    String.prototype.capitalize = function() {
      if (this.length == 1)
        return this.toUpperCase();
      return this.substr(0, 1).toUpperCase() + this.substr(1);
    };
    
  7. capitalize()
    var message = '';
    var student;
    String.prototype.capitalize = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    function print(message) {
      var outputDiv = document.getElementById('output');
      outputDiv.innerHTML = message;
    function printAll(students) {
      for (var i = 0; i < students.length; i += 1) {
        student = students[i];
        compileMessage(student);
      print(message);
    function printOne(student) {
      compileMessage(student);
      print(message);
    function compileMessage(input) {
      message += "<ul>";
      for ( var key in student ) {
        message += "<li>" + key.capitalize() + ": " + student[key] + "</li>";
      message += "</ul>";
    function search(students) {
      response = prompt("Please enter your student query: ");
      for (var i = 0; i < students.length; i += 1) {
        student = students[i];
        if ( student.name.toLowerCase() === response.toLowerCase() ) {
          printOne(student); 
          break;
    printAll(students);
    
  8. capitalize()
    String.prototype.capitalize = function() {
      if(this.length === 0) {
        return '';
      } else {
        return this.substr(0, 1).toUpperCase() + this.substr(1);
    };
    
  9. capitalize()
    String.prototype.capitalize = function() {
        return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
    function titleCase(title, minorWords) {
      var titleAr = title.toLowerCase().split(' '),
          minorWordsAr = minorWords ? minorWords.toLowerCase().split(' ') : [];
      return titleAr.map(function(e, i){return minorWordsAr.indexOf(e) === -1 || i === 0 ? e.capitalize() : e })
                    .join(' ');