Mon 25-Jul-2011
I want to delete the first word "Mon" with javascript jQuery. How can i do this ?
Remove first character in Excel To delete the first character from a string, you can use either the REPLACE function or a combination of RIGHT and LEN functions. Here, we simply take 1 character from the first position and replace it with an empty string ("").
Method #1: Using split() Method This task can be performed using the split function which performs a split of words and separates the first word of string with the entire words.
Open the document in Microsoft Word or another word processor. Move the mouse cursor to the beginning of the word you want to delete. Press and hold the left mouse button, then drag the mouse to the right until the entire word is highlighted. Press Backspace or Delete to delete the word.
If you don't want to split the string (faster, less memory consumed), you can use indexOf() with substr():
var original = "Mon 25-Jul-2011";
var result = original.substr(original.indexOf(" ") + 1);
var string = "Mon 25-Jul-2011";
var parts = string.split(' ');
parts.shift(); // parts is modified to remove first word
var result;
if (parts instanceof Array) {
result = parts.join(' ');
}
else {
result = parts;
}
// result now contains all but the first word of the string.
I wanted to remove first word from each items in Array of strings. I did that using split
, slice
, join
.
var str = "Mon 25-Jul-2011"
var newStr = str.split(' ').slice(1).join(' ')
console.log(str)
Run this code in console you will get the expected string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With