Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript add new line in string

//use 
 like this:
var newString = "this is on line 1 
and this is on line 2";
console.log(newString);
Comment

javascript string add new line

// let's say you want to make a code output game in a web page
// and you want to add a C# code
// do it like this!
// or you could use a textarea element and type it normally

const csCode = `
static double avrg(double num1, double num2, double num3, double num4){<br>
    &ThickSpace;double rslt = (num1 + num2 + num3 + num4) / 4;<br>
    &ThickSpace;return rslt;<br>
}<br>
int[] numbers = {10, 15, 8, 4, 2, 81, 90, 34, 23};<br>
int num1 = numbers[3];<br>
int num2 = numbers[7] - 1;<br>
int num3 = numbers[2] * numbers[1];<br>
double num4 = Math.Pow(numbers[3], 3);<br>
Console.WriteLine(avrg(num1, num2, num3, num4));
`;

// and then display it with innerHTML;
document.getElementById('code-display').innerHTML = csCode;

// the ThickSpace; will make it look like a tab keypress
// and now it will look good and will not generate on 1 single line
// and this works for TypeScript as well
Comment

PREVIOUS NEXT
Code Example
Javascript :: inheritance in class in js 
Javascript :: loop through async javascript -4 
Javascript :: onclick multiple functions react 
Javascript :: node fs existssync 
Javascript :: Promises ex. 
Javascript :: check if form bootstrap is valid js 
Javascript :: pass setstate to child 
Javascript :: get downloadable link to s3 bucket object js 
Javascript :: service worker registration 
Javascript :: what is javascript runtime 
Javascript :: passing event handler to useEffeect 
Javascript :: charcodeat javascript 
Javascript :: event property value in angular 
Javascript :: get keys of object js 
Javascript :: headers with fetch 
Javascript :: react change background image on hover 
Javascript :: node .env file example 
Javascript :: jquery copy to clipboard 
Javascript :: get width of screen 
Javascript :: iteratea on values map js 
Javascript :: javascript the event loop 
Javascript :: Random number given a range js 
Javascript :: jquery ajax send custom data after serialize 
Javascript :: (node:9130) electron: Failed to load URL: http://localhost:5000 
Javascript :: what is a for loop in javascript 
Javascript :: simple javascript 
Javascript :: generate unique random number in javascript 
Javascript :: convert integer month to string month react native 
Javascript :: redux devtools config 
Javascript :: setTimeout(() = { console.log(i);}, 100); 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =