Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js first letter uppercase

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|s)S/g, function(a) { return a.toUpperCase(); });
};
Comment

capitalize first letter of every word javascript

text.replace(/(^w|sw)/g, m => m.toUpperCase());
// Explanation:
// 
// ^w : first character of the string
// | : or
// sw : first character after whitespace
// (^w|sw) Capture the pattern.
// g Flag: Match all occurrences.

// Example usage:

// Create a reusable function:
const toTitleCase = str => str.replace(/(^w|sw)/g, m => m.toUpperCase());

// Call the function:
const myStringInTitleCase = toTitleCase(myString);

Comment

javascript uppercase first letter of each word

const toTitleCase = (phrase) => {
  return phrase
    .toLowerCase()
    .split(' ')
    .map(word => word.charAt(0).toUpperCase() + word.slice(1))
    .join(' ');
};

let result = toTitleCase('maRy hAd a lIttLe LaMb');
console.log(result);
Comment

capitalize first letter javascript

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

console.log(capitalizeFirstLetter('foo bar bag')); // Foo
Comment

javascript capitalize first letter

const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
Comment

javascript string first letter lowercase

// for lowercase on first letter
let s = "This is my string"
let lowerCaseFirst = s.charAt(0).toLowerCase() + s.slice(1)
Comment

javascript uppercase first letter of each word

const str = 'captain picard';

function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

const caps = str.split(' ').map(capitalize).join(' ');
caps; // 'Captain Picard'
Comment

capitalize first letter of all word typescript

//Altered, "capitalize all words of a string" (javascript by Grepper on Jul 22 2019) answer to compatible with TypeScript

var myString = 'abcd abcd';

capitalizeWords(text){
  return text.replace(/(?:^|s)S/g,(res)=>{ return res.toUpperCase();})
};

console.log(capitalizeWords(myString));

//result = "Abcd Abcd" 

Comment

uppercase first letter of each word javascript

const str = 'FIDEURAM VITA';

function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}

const caps = str.split(' ').map(capitalize).join(' ');
caps; // 'Fideuram Vita'
Comment

return first letter of string javascript in uppercase

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

console.log(capitalizeFirstLetter('foo')); // Foo
Comment

first letter tuUppercase

const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string[0].toUpperCase() + string.slice(1)
Comment

capitalize first carater js

const capitalize = (s) => {
  if (typeof s !== 'string') return ''
  return s.charAt(0).toUpperCase() + s.slice(1)
}

capitalize('flavio') //'Flavio'
capitalize('f')      //'F'
capitalize(0)        //''
capitalize({})       //''
Comment

js first letter to uppercase

function capitalizeFirstLetter(name) {
    return name.replace(/^./, name[0].toUpperCase())
}
Comment

javascript capitalize first letter of each word

function titleCase(str) {
   var splitStr = str.toLowerCase().split(' ');
   for (var i = 0; i < splitStr.length; i++) {
       // You do not need to check if i is larger than splitStr length, as your for does that for you
       // Assign it back to the array
       splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);     
   }
   // Directly return the joined string
   return splitStr.join(' '); 
}

document.write(titleCase("I'm a little tea pot"));
Comment

how to capitalize first letter javascript

const names = ["alice", "bob", "charlie", "danielle"]
// -->        ["Alice", "Bob", "Charlie", "Danielle"]

//Just use some anonymous function and iterate through each of the elements in the array
//and take string as another array
let namescap = names.map((x)=>{
    return x[0].toUpperCase()+x.slice(1)
    
})
console.log(namescap)
Comment

capitalise first letter js

const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string.charAt(0).toUpperCase() + string.slice(1)
Comment

first letter of each word in a sentence to uppercase javascript

function capitalizeTheFirstLetterOfEachWord(words) {
   var separateWord = words.toLowerCase().split(' ');
   for (var i = 0; i < separateWord.length; i++) {
      separateWord[i] = separateWord[i].charAt(0).toUpperCase() +
      separateWord[i].substring(1);
   }
   return separateWord.join(' ');
}
console.log(capitalizeTheFirstLetterOfEachWord("my name is john"));
Comment

js first character uppercase

string.charAt(0).toUpperCase() + string.slice(1);
Comment

js capitalize first letter

// this will only capitalize the first word
var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();

alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());
Comment

javaSript string first words to upper case

function titleCase(str) {
  return str.toLowerCase().replace(/(^|s)S/g, L => L.toUpperCase());
}
Comment

capitalize first letter of string javascript

let val = '  this is test ';
val = val.trim();
val = val.charAt(0).toUpperCase() + val.slice(1);
console.log("Value => ", val);
Comment

uppercase first letter of each word javascript


//Without function
const str = 'FIDEURAM VITA';
const caps = str.split(' ').map(str =>str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()).join(' ')
caps; // 'Fideuram Vita'
Comment

how to capitalize first letter in javascript

function capitalize(word) {
    return word.charAt(0).toUpperCase() + word.toLocaleLowerCase().substring(1)
}
capitalize("bob");
Comment

how to change the first Letter to uppercase js

let name = 'john';
name = name.charAt(0).toUpperCase() + name.slice(1); //slice(index) return string from index to index

console.log(name); // John
Comment

Javascript Capitalize First Letter

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

console.log(capitalizeFirstLetter('foo')); // Foo
 Run code snippet
Comment

js capitalize first letter of each word

const titleCase = title => title
    .split(/ /g).map(word =>
        `${word.substring(0,1).toUpperCase()}${word.substring(1)}`)
    .join(" ");
Comment

Capitalize the first letter of string using JavaScript

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
Comment

make the first letter of a string upper case

>>> "hello world".title()
'Hello World'
>>> u"hello world".title()
u'Hello World'
Comment

first letter uppercase js

const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
Comment

how to check if the first letter of a string is capitalized or uppercase in js

/**** Check if First Letter Is Upper Case in JavaScript***/
function startsWithCapital(word){
    return word.charAt(0) === word.charAt(0).toUpperCase()
}

console.log(startsWithCapital("Hello")) // true
console.log(startsWithCapital("hello")) // false
Comment

js caps first letter

// Oneliner, get first character, replace it with first character in upper case
string.replace(string[0], string[0].toUpperCase())
Comment

capitalize first carater js

p.capitalize {
  text-transform: capitalize;
}
Comment

How to capitalize the first letter of a word in JavaScript

const word = "freecodecamp"

const capitalized =
  word.charAt(0).toUpperCase()
  + word.slice(1)
  
// Freecodecamp
// F is capitalized
Comment

uppercase first letter javascript

const names = ["alice", "bob", "charlie", "danielle"];

const namesCap = names.map((name) => {
  return `${name[0].toUpperCase()}${name.slice(1)}`;
});

console.log(namesCap);
Comment

capitalize first carater js

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

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

Uppercase first letter of variable

var str = "hello world";
str = str.toLowerCase().replace(/[a-z]/g, function(letter) {
    return letter.toUpperCase();
});
alert(str); //Displays "Hello World"
Comment

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

uppercase-the-first-letter-of-a-string-using-javascript/

const name = 'avengers'
const userName = name.charAt(0).toUpperCase() + name.slice(0)

console.log(userName)
// Output: Aavengers
Comment

javascript capitalize first letter

function capitalizeFirstLetter(string) {
     return string.charAt(0).toUpperCase() + string.slice(1);
}

Comment

how to make first letter uppercase in javascript

var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();

alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());
Comment

How do I make the first letter of a string uppercase in JavaScript?

//1 using OOP Approach 
Object.defineProperty(String.prototype, 'capitalize', {
  value: function() {
      return this.charAt(0).toUpperCase()+ this.slice(1).toLowerCase();
  },
  enumerable: false
});

function titleCase(str) {
  return str.match(/wS*/gi).map(name => name.capitalize()).join(' ');
}
//-------------------------------------------------------------------
//2 using a simple Function 
function titleCase(str) {
  return str.match(/wS*/gi).map(name => capitalize(name)).join(' ');
}
function capitalize(string) {
  return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
Comment

uppercase first letter js

function ucwords (str) {
  return (str + '').replace(/^([a-z])|s+([a-z])/g, function ($1) {
    return $1.toUpperCase();
  });
}

console.log(ucwords("hello world"));
Comment

first letter string uppercase javascript

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

javascript first letter uppercase

const upperCase = function(names){
    const toLower = names.toLowerCase().split(' ');
    const namesUpper = [];
    for(const wordName of toLower){
        namesUpper.push(wordName[0].toUpperCase() + wordName.slice(1));
    }
    return namesUpper.join(' ');
}
Comment

capitalize first letter in array of strings javascript


        for(var i = 1 ; i < newArr.length ; i++){
            newArr[i].charAt(0).toUpperCase();
        
Comment

javascript capitalize first letter of each word

// includeAllCaps is optional and defaults to false
// if includeAllCaps is set to true, it will Title Case words with all capital letters

// includeMinorWords is optional and defaults to false
// if includeMinorWords is set to true, it will minor words in the middle of the string

function toTitleCase(str, includeAllCaps, includeMinorWords) {
    includeAllCaps = (includeAllCaps ? (includeAllCaps == true ? true : false) : false);
    includeMinorWords = (includeMinorWords ? (includeMinorWords == true ? true : false) : false);
    var i, j, lowers;
    str = str.replace(/([^W_]+[^s-]*) */g, function (txt) {
        if (!/[a-z]/.test(txt) && /[A-Z]/.test(txt) && !includeAllCaps) {
            return txt;
        } else {
            return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
        }
    });

    if (includeMinorWords) {
        return str;
    } else {
        // Certain minor words should be left lowercase unless 
        // they are the first or last words in the string
        lowers = ['A', 'An', 'The', 'And', 'But', 'Or', 'For', 'Nor', 'As', 'At',
            'By', 'For', 'From', 'In', 'Into', 'Near', 'Of', 'On', 'Onto', 'To', 'With'
        ];
        for (i = 0, j = lowers.length; i < j; i++)
            str = str.replace(new RegExp('s' + lowers[i] + 's', 'g'),
                function (txt) {
                    return txt.toLowerCase();
                });

        return str;
    }
}

toTitleCase("FOO bar"); // FOO Bar
toTitleCase("FOO bar", true); // Foo Bar
toTitleCase("a foo bar"); // A Foo Bar
toTitleCase("a foo in bar"); // A Foo in Bar
toTitleCase("foo of bar"); // Foo of Bar
toTitleCase("foo of bar", false, true); // Foo Of Bar
Comment

Captalize first letter javascript

function ucfirst(str,force){
          str=force ? str.toLowerCase() : str;
          return str.replace(/()([a-zA-Z])/,
                   function(firstLetter){
                      return   firstLetter.toUpperCase();
                   });
     }
Comment

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

JavaScript Capitalize First Letter

 const capitalize = ([first, ...rest]) => first.toUpperCase() + rest.join("").toLowerCase(); 
Comment

first letter of string in uppercase using javascript

function capFirst(str) {
     return str[0].toUpperCase() + str.slice(1);
 }

console.log(capFirst('hello'));
//output 
//Hello
Comment

capitalize first letter of a string

const name = 'flavio'
const nameCapitalized = name.charAt(0).toUpperCase() + name.slice(1)
Comment

Capitalize first letter

String name;

BufferedReader br = new InputStreamReader(System.in);

String s1 = name.charAt(0).toUppercase());

System.out.println(s1 + name.substring(1));
Comment

first Letter as Capital

string.charAt(index)
Comment

Captalize all words first letter javascript

function ucwords(str,force){
  str=force ? str.toLowerCase() : str;  
  return str.replace(/()([a-zA-Z])/g,
           function(firstLetter){
              return   firstLetter.toUpperCase();
           });
}
Comment

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

How to capitalize the first letterr in an array

const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());

console.log(capitalize);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery scroll left animation 
Javascript :: react native textinput lowercase 
Javascript :: loop json 
Javascript :: js rounding 
Javascript :: react native get numeric random string length of 5 characters 
Javascript :: angular form set value without fire event 
Javascript :: scrollview refresh react native 
Javascript :: javascript json download 
Javascript :: convert binary to decimal javascript 
Javascript :: javascript sleep 1 second 
Javascript :: error: Error: Unable to resolve module `react-native-gesture-handler` from `node_modules@react-navigation ativelibmoduleScrollables.js`: react-native-gesture-handler could not be found within the project. 
Javascript :: NullInjectorError: No provider for HttpHandler! 
Javascript :: discord js user has role 
Javascript :: js delete element by id 
Javascript :: document ready jquery 
Javascript :: fetch then then return value 
Javascript :: javascript add adjacent html 
Javascript :: javascript read json file 
Javascript :: javascript checkbox checked event 
Javascript :: fullscreen mode javascript 
Javascript :: how to position View absolute react native 
Javascript :: jquery create div element 
Javascript :: mongoose required 
Javascript :: get payable amount ethereum solidity 
Javascript :: float to string javascript 
Javascript :: conditionally set checkbox state in React 
Javascript :: useswr 
Javascript :: react/ionic ion-app undefined 
Javascript :: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead 
Javascript :: sort an array by the laster letter of element javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =