Import file path example  file://F:/js_html_test/image/tisssmg.jpg   win

window.alert('')     Popup

console.log('')     Browser console output ( Printing )

style.fontSize = '35px'   The calculated data becomes 35 Pixel display

style.display='block'   Equal to opening hidden content
 
<p id="demo" style="display:none">html I can't be seen , You need to have an open effect </p>     this P Field hiding

<br>     Line break

var Declare a variable  
var a = 1;
var a;         No impact a=1, Name the variable to ; Division No .

>>> calculation :

=   assignment
+=  1+=1 == 1+1
-=  7-=1 == 1-1
*   ride
/   except
%   Take mold
++   Incremental
--   Decreasing
*=   Multiply before and after
/=   Before and after

typeof         and python type equally Test data type

a  = 'i'+ 4 + 2 
b  =  4 + 2 + 'i'
a The result is  i42
b The result is  6i

var x = " China is the hometown of porcelain , therefore china And \"China( China )\" Same name .";
Escape sequence \" Insert double quotes in string  

String and number concatenation , Number before , Figure first , Number after , Splicing data .
 
<button οnclick="this.innerHTML=Date()"> Time is ?</button>     Direct change of button operation

txt.length   plus length return txt Length of string

\         You can wrap a text string with a backslash .

var str = "The full name of China is the People's Republic of China.";
var pos = str.indexOf("China");    indexOf() Method returns the first occurrence of the specified text

var res = str.match(/ain/g); 
Executing a pair of letters in stringing “ain”(/ain) The overall situation of (/g) search , And show matches .

str.replace("Microsoft","W3School");
Microsoft” Replace with “W3School

text.toUpperCase()     Convert string to uppercase
text.toLowerCase()     Convert string to lowercase

var str = "a,b,c,d,e,f";
var arr = str.split(",");  split according to , Split a string into arrays

>>> number :

var a = 188888888888888888 Will be accurate to 15 position , Display at most 15 position

Floating point calculation is not always accurate
To calculate floating point numbers correctly , You can first multiply and divide floating-point numbers , Can get accurate calculation value

Division multiplication subtraction Will try to convert a string to a number , Addition does not .
Division multiplication subtraction Will try to convert a string to a number , Addition does not .

100/'ddd' Divide by a non numeric string to get NaN(Not a Number)

isNaN()   Method to determine whether it is a number   Yes number return TRUE

NaN Yes no number , however typeof NaN return number  

Infinity When the value cannot be calculated , Returned value , For reference
0/ Any number   All for Infinity 

Prefix is 0x Is resolved to hexadecimal

toString() Method to cardinality 2 reach 36 Output string

valueOf()   Return to number

toExponential() Method returns a string , Contains rounding numbers and uses exponential representation .

toFixed() Method to round a number to a given number of digits .

toPrecision() Method returns a string , It contains a number written in the specified length .

Number() Method to convert a variable to a number . You can also convert dates to numbers .

parseInt() Convert string to number , Integer type .( The number in front can be converted to the number in front , The number is followed by a string and cannot be converted , Get one NaN)

parseFloat() Convert string to number , Can have floating-point data . Same as above , Only the first one will be converted , as parseFloat('111.11 DDD')

var x = Number.MIN_VALUE;     obtain js minimum value
var x = Number.MAX_VALUE;       obtain js Maximum

var x = Number.POSITIVE_INFINITY;     Infinite data       Infinity
var x = Number.NEGATIVE_INFINITY;     Indicates negative infinity of data     -Infinity

var x = 1 / 0;     The result is equal to infinity    Infinity
var x = -1 / 0;   The result is equal to negative infinity    -Infinity

100 / "Apple"   Number divided by non string , The result is equal to NaN
 
var x = 6;
document.getElementById("demo").innerHTML = x.MAX_VALUE;     On variables , Expressions or values use numeric attributes
 undefined

>>> Digital method :

Math.PI   Returns the ratio of circle circumference to diameter    3.14159....

Math.round(x)   return x The value rounded to the nearest integer , First place only as  4.5 = 5    4.4 = 4  4.4999999 = 4

Math.pow(x,y) return x Of y Value of power    Math.pow(8,2) ==  8^2 = 64

Math.sqrt(x) return x Square root of :      Math.sqrt(64) =  8  

Math.abs(x) return x Absolute value of :       Math.abs(-4.4); = 4.4

Math.ceil(x) Round a number to the nearest whole number   Math.ceil(4.00001)  = 5

Math.floor(x) The number is rounded down to the nearest integer value    Math.ceil(4.00001)  = 4

Math.sin(x) return x( In radians ) Sine of  "The sine value of 90 degrees is " + Math.sin(90 *
Math.PI / 180); = 1
Math.cos(x) return x( In radians ) Cosine of  "The cosine value of 0 degrees is " + Math.cos(0 *
Math.PI / 180); = 1

Math.max() Returns the highest value in the parameter list :  Math.max(0, 150, 30, 20, -8, -200); = 150 
Math.min() Returns the lowest value in the parameter list :  Math.min(0, 150, 30, 20, -8, -200); = -200

Math.random() generate 0-1 Random number between   as  0.8620973249208497

Math.floor(Math.random() * 10)       return 0 And 9 Random integer between ( Both contain )
Math.floor(Math.random() * 100)       return 0 And 99 Random integer between ( Both contain )
Math.floor(Math.random() * 101)       return 0 And 100 Random integer between ( Both contain )
Math.floor(Math.random() * 10) + 1)   return 1 And 10 Random integer between ( Both contain )
Math.floor(Math.random() * 100) + 1) return 1 And 100 Random integer between ( Both contain )

Math.floor(Math.random() * (max - min)) + min;      
getRndInteger(0,10)       return 0-9 Random number between     Contains only x Not included y

Math.floor(Math.random() * (max - min + 1) ) + min;   
getRndInteger(0,10)       return 0-10 Random number between   x and y Can be included

>>> date
Date()           Get current date

getFullYear()     Return date and full year      var d = new Date();    d.getFullYear()   

getTime()         Function return 1970.1.1 Milliseconds from start to present :    1564543577982
   
setFullYear()     Method to set the year of the date object :  var d = new Date(); d.setFullYear(2020);
  return Fri Jul 31 2020 11:26:54 GMT+0800 ( China standard time )

toUTCString()     Method to convert a date to UTC character string ( Date display standard ) var d = new Date();  d.toUTCString();

getDay()         Method returns the week name as a number   var d = new Date();  d.getDay();   Return week number , Number of weeks
as   var d = new Date();    var days =
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
 days[d.getDay()];
You can use arrays to display the names of the weeks :

>>>JavaScript array

var cars = ["Audi", "BMW", "porsche"];   Create array
    document.getElementById("demo").innerHTML = cars[0];   Get array index 0 start

cars[0] = "Volvo";
    document.getElementById("demo").innerHTML = cars;   Replace index in array as 0 Content of

    document.getElementById("demo").innerHTML = cars.length; == 4   Count Reg 4
    
cars=["BMW","Volvo","Saab","Ford"];
for (var i=0;i<cars.length;i++){
    document.write(cars[i] + "<br>");
}                                             JavaScript in for How to use cycle

var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
  fruits.push("Kiwi");
  document.getElementById("demo").innerHTML = fruits;
}
                             use push() Adding elements to an array

var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;

function myFunction12() {
  fruits[fruits.length] = "Lemon";
  document.getElementById("erer").innerHTML = fruits;
}                          length Property provides a push() Method to attach new elements to an array .

    
var fruits, text, fLen, i;
fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[6] = "Lemon";

fLen = fruits.length;
text = "";
for (i = 0; i < fLen; i++) {
  text += fruits[i] + "<br>";
}                                                  
document.getElementById("demo").innerHTML = text;   Add elements with high index to create undefined “ hole ”.

fruits instanceof Array;
Array.isArray(fruits);       Two methods to determine whether it is an array , Return when array true   Otherwise return false

fruits.push();        Direction array fruits Add an element element to
fruits.pop();         delete fruits Last element in array
fruits.join();       Method to concatenate array elements into a string
fruits.unshift();     Add element to beginning of array
fruits.shift();     Delete first element in array

var myGirls = ["Emma", "Isabella"];
var myBoys = ["Jacob", "Michael", "Ethan"];
var myChildren = myGirls.concat(myBoys);       concat() Method for merging ( connect ) array ( Connect two arrays )

var myChildren = arr1.concat(arr2, arr3);      concat() Method for merging ( connect ) array ( Connect three arrays )  
Can connect multiple
 
fruits.splice()       Two parameters , The first is where to insert the array , The second parameter is not required , Insert to replace , Replace several
fruits.toString()     Convert array to string , Comma separated
fruits.unshift()       Method to add a new element to the beginning of the array
fruits.shift()         Method to delete the first element of an array ( And all other elements “ displacement ” To the left )

>>>>>JavaScript Array sorting

fruits.sort()                               Sort the first letters in alphabetical order
fruits.reverse()                             Method to invert elements in an array .  
    fruits.sort();fruits.reverse();     By combination sort() and reverse(), You can sort arrays in descending order .

    
    
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;  

function myFunction() {
  points.sort(function(a, b){return a - b});
  document.getElementById("demo").innerHTML = points;
}                                              Sort arrays in ascending order

var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;  

function myFunction() {
  points.sort(function(a, b){return b - a});
  document.getElementById("demo").innerHTML = points;
}                                             Sort arrays in descending order

var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;  

function myFunction() {
  points.sort(function(a, b){return 0.5 - Math.random()});
  document.getElementById("demo").innerHTML = points;
}                                             Random sorting of arrays

var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = myArrayMin(points);

function myArrayMin(arr) {
  return Math.min.apply(null, arr);
}                                            Math.min   Calculate the minimum

var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = myArrayMax(points);

function myArrayMax(arr) {
  return Math.max.apply(null, arr);
}                                            Math.max   Calculate the maximum

var cars = [
  {type:"BMW", year:2017},
  {type:"Audi", year:2019},
  {type:"porsche", year:2018}
];

displayCars();

function myFunction() {
  cars.sort(function(a, b){return a.year - b.year});
  displayCars();
}

function displayCars() {
  document.getElementById("demo").innerHTML =
  cars[0].type + " " + cars[0].year + "<br>" +
  cars[1].type + " " + cars[1].year + "<br>" +
  cars[2].type + " " + cars[2].year;
}                                              Sort array by year      

var cars = [
  {type:"BMW", year:2017},
  {type:"Audi", year:2019},
  {type:"porsche", year:2018}
];

displayCars();

function myFunction() {
  cars.sort(function(a, b){
    var x = a.type.toLowerCase();
    var y = b.type.toLowerCase();
    if (x < y) {return -1;}
    if (x > y) {return 1;}
    return 0;
  });
  displayCars();
}

function displayCars() {
  document.getElementById("demo").innerHTML =
  cars[0].type + " " + cars[0].year + "<br>" +
  cars[1].type + " " + cars[1].year + "<br>" +
  cars[2].type + " " + cars[2].year;
}                                             Sort by the first letter of the string

>>> Array iteration

Array.forEach()         Function methods are called once for each element in the array
Array.map()                 Array elements execute functions to create new arrays
Array.filter()             Array elements create a new array from all array elements of the function test
Array.reduce()             The sum of all the numbers in the array , And it's the same as the addition and division algorithm
Array.reduceRight()     Same function as above , It just adds up from left to left
Array.every()             Whether all in the array meet the conditions , Pass the test   By returning True, Otherwise return false
Array.some()             Whether part of the array satisfies the condition , Or with conditions , Pass test return True, Otherwise return false
Array.indexOf()              Query the array for where the element exists , Return the corresponding position number ,
Array.lastIndexOf()     If there is the same element in Togo in the array , Will return the location parameter of the last element
Array.find()                Find the first element in the array that meets the condition , And print it out
Array.findIndex()         Find the first element in the array that meets the condition , And print out his index

constructor     Returns the object constructor function of the property variable for example   "john".constructor   function String() {
[native code] }

String(x)              Method to convert a number to a string .
toString(x)         Method to convert a number to a string .

Array.isArray()     Confirm whether the variable parameter is an array

isDate()             Check whether it is a date ( Homemade )
    function isDate(myDate) {
      return myDate.constructor.toString().indexOf("Date") > -1;
    }

Boolean( 9 > 8 )     Judge whether the conditions are correct , Return if correct True Otherwise return false

Boolean()     The Boolean with all true values is True,0 The Boolean value of is false,-0 The Boolean value of is false

The Boolean value is false The types of are :
    0,-0,'',undefined,null,false,NaN These values are all Boolean false
    

   

    

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )java Four functional interfaces ( a key , simple )HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees os Simple use of module