All things in JavaScript are objects: strings, numbers, arrays, functions ...
The length property of the string object to obtain the lengths of the strings:
var message= "Hello world!"; var x=message. length
;
First, JavaScript class
JavaScript is an object-oriented language, but JavaScript does not use classes.
In JavaScript, classes are not created and objects are not created through classes (as in other object-oriented languages).
JavaScript is based on prototype, not class-based.
JavaScript for...in Loops
The JavaScript for...in statement loops through the properties of the object.
<p> Click the button below to iterate through the properties of the object "person". </p><button onclick= "myFunction ()" > click here </button><p id= "Demo" ></p><script> function myFunction () {var x; var txt= ""; var person={fname: "One", lname: "Two", Age:3 for the person ) {txt=txt + PERSON[X];} document.getElementById ("Demo"). innerhtml=txt;} </script>
Second, Number object (numeric object)
JavaScript has only one numeric type.
JavaScript numbers
JavaScript numbers can be used or written without using a decimal point:
Instance
var pi=3.14; Use the decimal point var x=34; Do not use decimal points
The maximum or minimum number can be written by means of the scientific (exponential) notation:
Instance
var y=123e5; 12300000var z=123e-5; 0.00123
All JavaScript numbers are 64-bit precision
Integers (not using decimal or exponential notation) are up to 15 bits.
The maximum number of decimal digits is 17, but the floating-point operation is not always 100% accurate:
Octal and hexadecimal
If the prefix is 0, JavaScript interprets numeric constants as octal numbers, and if the prefixes are 0 and "X", they are interpreted as hexadecimal numbers.
Tip: Never write 0 in front of the number unless you need to make an octal conversion.
Three, String object
1) indexOf () method
Use IndexOf () to position the first occurrence of a specified character in a string.
<script type= "Text/javascript" >var str= "Hello world!" document.write (Str.indexof ("Hello") + "<br/>") document.write (Str.indexof("World") + "< br/> ") document.write (Str.indexof (" World "))</script>
2) Match () method
Use Match () to find a specific character in the string and, if found, to return the character.
<script type= "Text/javascript" >var str= "Hello world!" document.write (Str.match ("World") + "<br/>") document.write (Str.match("World") + "<BR/ > ") document.write (Str.match (" worlld ") +" <br/> ") document.write (Str.match(" world! " ))</script>
3) How to replace characters in a string-replace ()
Use the Replace () method to replace characters with some characters in a string.
<script>var str= "Tupian1 jpg1"document.write (str.replace ("Jpg1", "Png1")</ Script>
In addition, these methods can define a variable to accept them and then print.
Iv. Date (date) object
Date () Gets the day:
document.write (Date ());
Operation Date
By using a method for a Date object, we can easily manipulate the date.
<script>var mydate=New Date () mydate.setfullyear (2008,7,9) document.write ( mydate)</script>
Note: The parameter that represents the month is between 0 and 11. That is, if you want to set the month to August, the parameter should be 7.
V. Array (array) object
Defines an array and assigns a value to it.
var mycars=New Array () mycars[0]= "Saab"mycars[1]= "Volvo"mycars[2]= " BMW "
Use the for...in declaration to loop through the elements in the output array.
<script type= "Text/javascript" >var xvarnew Array () mycars[0] = " Saab "mycars[1] =" Volvo "mycars[2] =" BMW "for in +" <br/> ")} </script>
VI. Math (Arithmetic) object
1) Random ()
Use random () to return a number from 0 to 1.
<script type= "Text/javascript" >document.write (Math.random ())</script>
The number within 1-100, multiplied by 100, is possible.
2) Max () and Min ()
Max ()
Returns the larger number of two given number
<script type= "Text/javascript" >document.write (Math.max (5,7) + "<br/>") document.write ( Math.max (-3,5) + "<br/>") document.write (Math.max (-3,-5) + "<br/>") document.write ( Math.max (7.25,7.30))</script>
Min ()
Returns the smaller number of two given digits (same as Max ())
Vii. REGEXP objects (regular expressions)
REGEXP is the abbreviation for regular expressions.
When you retrieve a text, you can use a pattern to describe what you want to retrieve. REGEXP is this pattern.
The simple pattern can be a single character.
More complex patterns include more characters and can be used for parsing, format checking, substitution, and so on.
You can specify the location of the search in a string, the type of character to retrieve, and so on.
Define REGEXP
The RegExp object is used to store the retrieval mode.
Define the RegExp object with the New keyword. The following code defines the RegExp object named Patt1, whose pattern is "e":
var patt1=new RegExp ("E");
Methods for REGEXP objects
The RegExp object has 3 methods: Test (), exec (), and compile ().
Expression Reference URL:
Http://www.w3school.com.cn/jsref/jsref_obj_regexp.asp
http://msdn.microsoft.com/zh-cn/library/ae5bf541 (v=vs.90). aspx
20141128-javascript Object