0

if I have :

   var string = "Something";

and I want to remove [e]

and get:

   string = "Somthing";

How can I do this?

user3806832
  • 663
  • 9
  • 22
  • Do you want to remove every instance of the letter `e`, a single instance of the letter `e`, or any character appearing at index 3? – Jordan Running Jun 30 '15 at 02:30
  • You've done it already. Assign it again without `e`, then you will have your job done. Search for "string replace javascript" and you'll be amazed by the tremendous amount of resources at your hands to achieve what you've set out to achieve. – Amit Joki Jun 30 '15 at 02:30
  • http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript – ecarrizo Jun 30 '15 at 02:30
  • 1
    I want to remove the character appearing at index 3 – user3806832 Jun 30 '15 at 02:31
  • possible duplicate of [Remove a character at a certain position in a string - javascript](http://stackoverflow.com/questions/11116501/remove-a-character-at-a-certain-position-in-a-string-javascript) – ecarrizo Jun 30 '15 at 02:37

2 Answers2

1
string = string.replace(/\e/g, '');

should do the trick.

dgrundel
  • 568
  • 3
  • 7
0

To access various letters in the array, you can use charAt():

for(var i = 0; i < string.length; i++){
  console.log(string.charAt(i));
}

To find the e:

for(var i = 0; i < string.length; i++){
  if(string.charAt(i) === `e`){
    console.log("found an e");
  }
}

To remove the 'e':

var string = "something";
var arr = string.split(''); //["s", "o", "m", "e", "t", "h", "i", "n", "g"]
for(var i = 0; i < arr.length; i++){
  if(arr[i] === 'e'){
    arr.splice(i,1);
  }
}

arr.join('');   //"somthing"
jojo
  • 1,135
  • 1
  • 15
  • 35