+ 1

How to set any string at their first position in Javascript

Var a = "This is a string "; Var concatenate = a.concate("This is nothing"); In this way, Concatenate will add in the last after a(var) My question is What if I have to add the same concatenate var at the first position or wherever I like to put in a (var)

15th Mar 2023, 6:02 AM
Dinesh Pal :)
Dinesh Pal :) - avatar
3 Respostas
+ 3
In Javascript, a string is immutable. This means that you cannot change it after you create it. But a variable that stores the string, can be changed, and it can point to a new string instead. There are many ways to construct new strings from existing data. - using the concat method of an existing string (mind your spelling!) - simply use the + addition operator - use template literals `` - plenty of other ways to make string from other data types Basic example: var str = "word"; str = "first " + str; // result: "first word"
15th Mar 2023, 6:21 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Divaskrp :) you can use concat also to put the string first: var a = "This is a string "; var concatenate = "This is nothing".concat(a);
15th Mar 2023, 8:37 PM
Brian
Brian - avatar
+ 1
you can define your own insert function https://code.sololearn.com/Wdd6sLkDCMuD/?ref=app
16th Mar 2023, 5:34 AM
Bob_Li
Bob_Li - avatar