How to put variable into quotes? [duplicate] - javascript

This question already has answers here:
Double quote in JavaScript string
(4 answers)
How to interpolate variables in strings in JavaScript, without concatenation?
(17 answers)
How to insert variables in JavaScript strings?
(4 answers)
Closed 3 years ago.
Would like to put the variable ( txt.txt.charAt(char_counter) )in quotes.
Anyone can help?
Thanks
var pattern_node = document.createTextNode("Zeichen:"+txt.txt.charAt(char_counter)+" "+ str.str +" gesendet");

ES6/ES2015 feature, template string
var pattern_node = document.createTextNode(`Zeichen:${txt.txt.charAt(char_counter)} ${str.str} gesendet`);

Related

How to replace a string in javascript only when it's comes before another string using regex? [duplicate]

This question already has answers here:
REGEX: Capture Filename from URL without file extension
(5 answers)
JavaScript Regexp to replace a value only when it follows certain characters?
(2 answers)
Closed 3 years ago.
I want to replace xx with . in this string 100x100/<name>xx-somename-xxjpg but only xx comes next to jpg.
'100x100/<name>xx-somename-xxjpg'.replace(/(xx(jpg|jpeg|png))/,'$')
What I get -> 100x100/<name>xx-somename-$
What I expect-> 100x100/<name>xx-somename-.jpg
How do I do it?
'100x100/<name>xx-somename-xxjpg'.replace(/(xx)(?=jpg|jpeg|png)/,'.')

Get one or more string which starts and ends with into array [duplicate]

This question already has answers here:
Regular expression to extract text between square brackets
(15 answers)
Getting content between curly braces in JavaScript with regex
(5 answers)
Closed 3 years ago.
How to loop and get all string starts with { and ends with } into an array? For example:
Hi {recipient}, calling from {sender}. Your {item} has arrived.

Why does a = (b=3,c=7) assign 7 to a in javascript? [duplicate]

This question already has answers here:
What is the point of wrapping JavaScript statements in parentheses?
(2 answers)
What does the comma operator do in JavaScript?
(5 answers)
Closed 5 years ago.
I came across an interesting thing in javascript. The following code prints 7.
a = (b=3 , c=7);
document.write(a);
I would like to know how/why this happens.

How to format string in JS? [duplicate]

This question already has answers here:
JavaScript .replace only replaces first Match [duplicate]
(7 answers)
Closed 6 years ago.
I would like to have the result :
28,12,2016
From this string "28/12/2016"
I tried :
("28/12/2016").replace('/',',');
==>"28,12/2016"
I don't know how to delete the second /and the " "
use split and join method
var a="28/12/2016";
var ans=a.split("/").join(",");
console.log(ans);

extracting text between two characters [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 6 years ago.
Having a string like:
"*this* not that"
I can select *this*
\*(.*?)\*
but I'm not able to get only this.
what I am trying to achieve is to replace -this- by a new string. What's the easiest way to do that ?
you can try:
"*this* not that".replace(/\*.*\*/,'*new_string*');
//"*new_string* not that"

Categories

Resources