+ 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)
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"
+ 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);
+ 1
you can define your own insert function
https://code.sololearn.com/Wdd6sLkDCMuD/?ref=app