Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to assign char in a string javascript

function replaceAt(str, index, newChar) {
    function replacer(origChar, strIndex) {
        if (strIndex === index)
            return newChar;
        else
            return origChar;
    }
    return str.replace(/./g, replacer);
}

let str = 'Hello World';
str = replaceAt(str, 1, 'u');
console.log(str); // Hullo World
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: react hooks example 
Javascript :: fake delay in fetch 
Javascript :: stack overflow js bubble sort 
Javascript :: linear search algorithm in javascript 
Javascript :: simultaneos mouse buttons clicked js 
Javascript :: JQuery UI Saving Sortable List 
Javascript :: same date to string in javascript minus and days difference 
Javascript :: calculate sum in empty array javascript 
Javascript :: noscript tag code string in react 
Javascript :: nodejs express routing get 
Javascript :: fcm node 
Javascript :: Firebase: Error (auth/invalid-api-key). 
Javascript :: strtok javascript 
Javascript :: You might have more than one copy of React in the same app. 
Javascript :: regular expression to validate m/d/yyyy HH:MM:SS AM 
Javascript :: mdn .includes 
Javascript :: javascript test if undefined 
Javascript :: havascript The toExponential() Method 
Javascript :: mouse over jest 
Javascript :: javascript filter array of objects 
Javascript :: react show view based on role permission 
Javascript :: onselect in zebra datepicker 
Javascript :: javascript get first entry from set 
Javascript :: input as html in console 
Javascript :: react axios POST using async await method with super constructor parent class 
Javascript :: jquery get table 
Javascript :: threejs heart 
Javascript :: can we use setstate inside build 
Javascript :: how to fetch data from json file in flutter 
Javascript :: javascript how do I measure the time of the loop 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =