Capitalize First Letter in an Array of Element Using JavaScript map() Last Updated : 10 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Capitalizing the first letter in an array element using JavaScript's map() method involves transforming each element by modifying its first character to uppercase. The map() function iterates over the array, applying the transformation to each element, and returning a new array with updated values.Here we have a basic example:Input: = ['javascript', 'html', 'css'];Output: = ['Javascript', 'Html', 'Css'];Example 1: Capitalizing the First Letter of Each WordIn this example, we iterate through each element in the fruits array, capitalize the first letter, and combine it with the rest of the word. The resulting array contains the capitalized fruit names. JavaScript const fruits = ['apple', 'banana', 'cherry', 'date']; const capitalizedFruits = fruits.map(fruit => { return fruit.charAt(0).toUpperCase() + fruit.slice(1); }); console.log(capitalizedFruits); Output[ 'Apple', 'Banana', 'Cherry', 'Date' ] Example 2: Capitalizing Each Word in an Array of SentencesIn this example we takes an array of sentences, splits each sentence into words, capitalizes the first letter of each word, and then rejoins the words, returning an array of capitalized sentences. JavaScript const sentences = ['hello world', 'javascript is fun', 'coding is creative']; const capitalizedSentences = sentences.map(sentence => { return sentence .split(' ') // Split the sentence into individual words .map(word => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize each word .join(' '); // Join the words back together into a sentence }); console.log(capitalizedSentences); Output[ 'Hello World', 'Javascript Is Fun', 'Coding Is Creative' ] We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript. Comment More infoAdvertise with us Next Article Capitalize First Letter in an Array of Element Using JavaScript map() H HGaur Follow Improve Article Tags : Misc JavaScript Web Technologies javascript-array JavaScript-Methods +1 More Practice Tags : Misc Similar Reads JavaScript - Delete First Character of a String To delete the first character of a string in JavaScript, you can use several methods. Here are some of the most common onesUsing slice()The slice() method is frequently used to remove the first character by returning a new string from index 1 to the end.JavaScriptlet s1 = "GeeksforGeeks"; let s2 = s 1 min read How to create a string by joining the elements of an array in JavaScript ? Given an array containing array elements and here we will join all the array elements to make a single string. To join the array elements we use arr.join() method. There are two methods by which we can create a string by joining the elements of an array: Table of Content Using arr.join() MethodUsing 2 min read How To Convert Map Keys to an Array in JavaScript? Here are the various methods to convert Map keys to an array in JavaScript1. Using array.from() MethodThe Array.from() method in JavaScript converts Map keys to an array by using 'Array.from(map.keys())'. JavaScriptlet map = new Map().set('GFG', 1).set('Geeks', 2); let a = Array.from(map.keys()); co 2 min read JavaScript - How to Find the First and Last Character of a String? Here are the various methods to find the first and last character of a string in JavaScript.1. Using charAt() MethodThe charAt() method retrieves the character at a specified index.JavaScriptconst s = "JavaScript"; const first = s.charAt(0); const last = s.charAt(s.length - 1); console.log(first); c 2 min read JavaScript - How to Make First Letter of a String Uppercase? Here are the different approaches to make the first letter of a string uppercase in JavaScript.1. Using charAt() with slice() Method (Most Common)The combination of charAt() and slice() is the simplest and widely used way to capitalize the first letter of a string.JavaScriptconst s1 = "javaScript"; 2 min read How to Capitalize the First Letter of a String Using Lodash? Capitalizing the first letter of a string consists of transforming only the initial character to uppercase while keeping the rest of the string in its original case. Below are the possible approaches to Capitalize the First Letter of a String Using Lodash:Table of ContentUsing _.capitalize() MethodU 2 min read JavaScript - Sort a String Alphabetically using a Function Here are the various methods to sort a string alphabetically using a function in JavaScript.1. Using split(), sort(), and join() MethodsThis is the most basic and commonly used method to sort a string alphabetically. The string is first converted into an array of characters, sorted, and then joined 2 min read How to Move a Key in an Array of Objects using JavaScript? The JavaScript array of objects is a type of array that contains JavaScript objects as its elements.You can move or add a key to these types of arrays using the below methods in JavaScript:Table of ContentUsing Object Destructuring and Map()Using forEach() methodUsing for...of LoopUsing reduce() met 5 min read How to convert a string into kebab case using JavaScript ? Given a string with space-separated or camel case or snake case letters, the task is to find the kebab case of the following string. Examples: Input: Geeks For GeeksOutput: geeks-for-geeksInput: GeeksForGeeksOutput: geeks-for-geeksInput: Geeks_for_geeksOutput: geeks-for-geeksBelow are the approaches 3 min read How to replace all dots in a string using JavaScript ? We will replace all dots in a string using JavaScript. There are multiple approaches to manipulating a string in JavaScript. Table of Content Using JavaScript replace() MethodUsing JavaScript Split() and Join() Method Using JavaSccript reduce() Method and spread operatorUsing JavaScript replaceAll() 4 min read Like