How to remove text from a string?
Posted By: Anonymous
I’ve got a data-123
string.
How can I remove data-
from the string while leaving the 123
?
Solution
var ret = "data-123".replace('data-','');
console.log(ret); //prints: 123
For all occurrences to be discarded use:
var ret = "data-123".replace(/data-/g,'');
PS: The replace function returns a new string and leaves the original string unchanged, so use the function return value after the replace() call.
Answered By: Anonymous
Related Articles
- Form field border-radius is not working only on the…
- Rolling Regression over several columns with NA´s
- OpenCL - Approximation of Pi via Monte Carlo…
- Examples of GoF Design Patterns in Java's core libraries
- binary search tree is not working properly, but the…
- How to use html template with vue.js
- insert tables in dataframe with years from 2000 to…
- Backbone Collection.fetch gives me Uncaught…
- Byte Array and Int conversion in Java
- python 3.2 UnicodeEncodeError: 'charmap' codec can't…
- Pandas pivot_table: filter on aggregate function
- How to print a string at a fixed width?
- Problems Installing CRA & NextJS from NPM…
- Is it possible to apply CSS to half of a character?
- What are the new features in C++17?
- Best way to replace multiple characters in a string?
- db.SaveChanges in ForEach causes 'New transaction is…
- how to send and receive data chunk by chunk in linux sockets
- Loading 16-bit (or bigger) immediate with a Arm…
- How can I pass a wct test while rearranging children…
- Jquery how to use this in a event datatable generated td row
- For-each over an array in JavaScript
- Print tables with 3 regression output models from rdrobust
- What is the scope of variables in JavaScript?
- Property or method "key" is not defined on the…
- SQL find sum of entries by date including previous date
- Fix top buttons on scroll of list below
- Sort table rows In Bootstrap
- Determining if an Object is of primitive type
- Program.Mattor(): not all code paths return a value.…
- ember.js and handlebars registerHelper function
- Executing elements inserted with .innerHTML
- Fast way of finding lines in one file that are not…
- pandas.DataFrame.from_dict faster alternative
- Create Restful webservices to call a stored procedure in C#
- Firebase cloud function onUpdate is triggered but…
- Git - Pushing code to two remotes
- Base64 decode snippet in C++
- How to save a video after changing its speed with…
- data.table vs dplyr: can one do something well the…
- Backbone click event binding not being bound to DOM elements
- How to filter a RecyclerView with a SearchView
- Programmatically generate url from path and params
- How to parse an RSS feed using JavaScript?
- Logging best practices
- C# parse FHIR bundle - read resources
- Quicker way to get all unique values of a column in VBA?
- How do I return the response from an asynchronous call?
- How can I access and process nested objects, arrays or JSON?
- Cant figure out what Im doing wrong. Unhandled…
- I need to sum values with specific condition
- VueJS & Laravel, do a post request when user…
- Accessing a Shared File (UNC) From a Remote,…
- What's the difference between eval, exec, and compile?
- C program that replace word in sentence to another word
- Unexpected end of JSON input while parsing
- How to Calculate Execution Time of a Code Snippet in C++
- Sorting Backbone Collections
- Obtain most recent value for based on index in a…
- Backbone.js - Given an element, how do I get the view?
- Add calculated column to df2 for every row entry in…
- Cannot make table responsive
- D3.js: Update barplot based on variable input
- How to change the color of vaadin-select-text-field…
- Regex on htaccess file gives INTERNAL REDIRECT error
- Use of PUT vs PATCH methods in REST API real life scenarios
- What does "Fatal error: Unexpectedly found nil while…
- How to aggregate values from a list and display in…
- How to code a modulo (%) operator in C/C++/Obj-C…
- How to get main JQuery Mobile page to display after…
- how to make column bool data to be true with the…
- How to convert an ArrayList containing Integers to…
- Backbone nested views - child view attributes…
- Ember link-to handlebars and jQuery DataTables
- Polymer 1.x: Observers
- Import Python Script Into Another?
- How can I set hours and minutes of date with oracle sql?
- boolean in an if statement
- How can I concat a child array to a parent array in…
- How to make the script wait/sleep in a simple way in unity
- How to use java.net.URLConnection to fire and handle…
- Returning an array using C
- Dynamically update values of a chartjs chart
- After a little scroll, the sticky navbar just is not…
- ember-data unsaved model is not discarded when…
- Am I paranoid? "Brutally" big Polymer website after…
- What is an optional value in Swift?
- Unable to set data attribute using jQuery Data() API
- Undo git update-index --assume-unchanged
- Calling class staticmethod within the class body?
- How to rename the keys of nested object in Javascript?
- NullpointerException error while working with…
- How do you clear the SQL Server transaction log?
- setTimeout function not working : javascript
- The request was aborted: Could not create SSL/TLS…
- Finding repeated words on a string and counting the…
- Why does C++ code for testing the Collatz conjecture…
- Testing Vue filters with jest
- Get value using key
- .gitignore and "The following untracked working tree…
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.