I am so close to getting this, but it just isn’t right. All I would like to do is remove the character r
from a string. The problem is, there is more than one instance of r
in the string. However, it is always the character at index 4 (so the 5th character).
Example string: crt/r2002_2
What I want: crt/2002_2
This replace function removes both r
mystring.replace(/r/g, '')
Produces: ct/2002_2
I tried this function:
String.prototype.replaceAt = function (index, char) { return this.substr(0, index) + char + this.substr(index + char.length); } mystring.replaceAt(4, '')
It only works if I replace it with another character. It will not simply remove it.
Any thoughts?
Related Posts:
- Replace spaces with dashes and make all letters lower-case
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- How to replace all occurrences of a string in JavaScript
- How to convert a string to an integer in JavaScript?
- How can I do string interpolation in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- Creating multiline strings in JavaScript
- Creating multiline strings in JavaScript
- Split string into array
- How do you reverse a string in-place in JavaScript?
- What is the correct way to check for string equality in JavaScript?
- JavaScript replace/regex
- Check if a variable is a string in JavaScript
- What’s the best way to convert a number to a string in JavaScript?
- Check if a variable is a string in JavaScript
- How to print elements from array with javascript
- How to remove text from a string?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- Delete first character of a string in Javascript
- ES6: Create Strings using Template Literals – Freecodecamp
- How do I check if string contains substring? [duplicate]
- How do I check if string contains substring?
- How can I get the last character in a string?
- How can I get the last character in a string?
- Count the number of occurrences of a character in a string in Javascript
- Converting an object to a string
- Anagrams finder in javascript
- How to interpolate variables in strings in JavaScript, without concatenation?
- How can I extract a number from a string in JavaScript?
- String.Format not work in TypeScript
- How to do case insensitive string comparison?
- Replace a character at a specific index in a string?
- How to remove part of a string?
- Escaping HTML strings with jQuery
- Replace all spaces in a string with ‘+’
- How to count string occurrence in string?
- Insert a string at a specific index
- Strip HTML from Text JavaScript
- window.location.replace() not working to redirect browser
- Strip all non-numeric characters from string in JavaScript
- Wildcard string comparison in Javascript
- Check if a JavaScript string is a URL
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How to do associative array/hashing in JavaScript
- How to play audio?
- How to write a countdown timer in JavaScript?
- TypeScript foreach return [duplicate]
- What does “javascript:void(0)” mean?
- What does this symbol mean in JavaScript?
- Go back button in a page
- ‘react-scripts’ is not recognized as an internal or external command
- After $npm install, Getting Error: Cannot find module ‘../lib/utils/unsupported.js’
- React Context vs React Redux, when should I use each one?
- Regular expression : match either of two conditions?
- jQuery AJAX submit form
- Difference between this and self in JavaScript
- How to remove all listeners in an element?
- How do I check if an object has a key in JavaScript?
- How to add a “readonly” attribute to an ?
- JQuery $(“#content”).append not working
- Difference between String replace() and replaceAll()
- Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded
- Counting words in string
- What’s “this” in JavaScript onclick?
- how to use react require syntax?
- document.getElementById(id).focus() is not working for firefox or chrome
- How to get unique values in an array
- How to fix Error: listen EADDRINUSE while using NodeJS?
- How to allow CORS in react.js?
- momentJS date string add 5 days
- When is a CDATA section necessary within a script tag?
- How to get scrollbar position with Javascript?
- where is create-react-app webpack config and files?
- “You may need an appropriate loader to handle this file type” with Webpack and Babel
- How to create checkbox inside dropdown?
- How do developers add “Smooth Transitions” to their sites?
- Exclude JS file from 404 error page
- Pass data from wordpress to javascript in JSON
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- Contact Form 7 – Uncaught TypeError: wpcf7.initForm is not a function [closed]
- Where is script-loader.php creating JS tags
- WP TinyMCE (Full + media ) – 4.8 JS Init Dynamicly
- Search for a keyword across post types in a Gutenberg component
- Calling a WordPress Custom JavaScript file
- print script on wordpress header after user registered
- How do I use this javascript correct with wordpress?
- Load external javascript files
- How to display different content on the same page using different URLS
- Replace script attr or link
- Remove escape characters from JSON string pulled from a database
- Client side pre-save Javascript hook on all admin pages
- WP Gutenberg – custom block with two content fields
- How to identify which javascript is being executed
- How to keep close a sub-menu under homepage? [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- Javascript not working on index.php but it is working on single post’s page