+ 2

How to change "letter" in a string

i want to change the second letter. i have tried this as an example: var a = "hay"; a[1] = "e"; document.write(a); but it doesnt work.

5th Sep 2018, 12:36 PM
David Agustinus
David Agustinus - avatar
5 Antworten
+ 2
Also a good idea to drop the code you have into a Code Playground Web project and provide a link to your Code Playground code so we can help you troubleshoot the specific issues you are running into. The Code Playground should be relatively easy to find in the website version of SoloLearn, but if you are in the app version, it can be accessed via the curly braces, green circle with plus sign to add a new project, then select the project type. Looking forward.
5th Sep 2018, 12:46 PM
Janning⭐
Janning⭐ - avatar
+ 2
This might be more suitable for what you're trying to accomplish: https://www.w3schools.com/jsref/jsref_replace.asp
5th Sep 2018, 12:50 PM
Janning⭐
Janning⭐ - avatar
+ 1
Probably a lot of other issues as well, but here's something useful to review: https://www.w3schools.com/jsref/met_doc_write.asp
5th Sep 2018, 12:44 PM
Janning⭐
Janning⭐ - avatar
+ 1
"hay" is a string that I think you're trying to treat as an array ...
5th Sep 2018, 12:48 PM
Janning⭐
Janning⭐ - avatar
+ 1
var a = "hay"; a = a.replace('a','E'); console.log(a);
9th Sep 2018, 3:34 AM
Mr Genesis
Mr Genesis - avatar