Just use the String replace
and toLowerCase
methods, for example:
var str = "Sonic Free Games"; str = str.replace(/\s+/g, '-').toLowerCase(); console.log(str); // "sonic-free-games"
Notice the g
flag on the RegExp
, it will make the replacement globally within the string, if it’s not used, only the first occurrence will be replaced, and also, that RegExp
will match one or more white-space characters.
Related Posts:
- How can I remove a character from a string using JavaScript?
- 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?
- 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
- How do I check whether a checkbox is checked in jQuery?
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- How can I check for “undefined” in JavaScript?
- How to make history.back() without getting a warning on the browser to reload the page?
- TypeError: Router.use() requires middleware function but got a Object
- What does jQuery.fn mean?
- Cannot find module ‘@angular-devkit/core’
- iFrame onload JavaScript event
- What is the difference between state and props in React?
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- How to convert JSON object to JavaScript array?
- How can I display a JavaScript object?
- JSLint says “missing radix parameter”
- How to handle ETIMEDOUT error?
- How to print HTML content on click of a button, but not the page?
- explode string in jquery
- How do I create and read a value from cookie?
- Check if a variable is of function type
- Bootstrap 4 Dropdown Menu not working?
- Truncate a string straight JavaScript
- Phone mask with jQuery and Masked Input Plugin
- JQuery get all elements by class name
- Remove specific characters from a string in Python
- Get class list for element with jQuery
- Object Dump JavaScript
- Convert array to JSON
- Is there a way to read standard input with JavaScript?
- How to disable scrolling temporarily?
- JSON.stringify (Javascript) and json.dumps (Python) not equivalent on a list?
- HTML/Javascript change div content
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- How to disable button in React.js
- What’s the effect of adding ‘return false’ to a click event listener?
- New line in JavaScript alert box
- What does wp-embed.min.js do in WordPress 4.4?
- Gutenberg – remove / add blocks with custom script
- Gutenberg extend blocks add new class name
- How do I add custom attributes to javascript tags in WordPress?
- wp_enqueue_script & constants?
- Resolving Javascript errors likely related to Gantry framework
- WordPress customizer get control
- How to load JS for specific screen size using wp_enqueue_script?
- I am trying to add current logged in user to my zoho chat
- Where to upload JavaScript file in WordPress
- Conditional save return on Gutenberg Block
- Can I alter the block editor’s paste text behavior?
- Headless wp with react. How to handle routes?
- Where to paste Google Map Snippet / JavaScript / CSS for WordPress integration
- Issues trying to get an element by id
- Change background video when scrolling reaches a certain ID
- Dynamically changing logo on scroll function [closed]
- Remove WordPress default registration client side validation?
- How could I add load more posts to my theme? [closed]
- Live Time on WP showing weirdly [closed]
- Javascript button to call custom fields data
- Table block variation with header section activated