js basis - Basic Package Type

1, the basic package type String
  var bz = new String("Li.Linda");
        bz.name = bz.substring (3); // attribute object
        bz.age = function () {// object methods
          return 25;
        }
        console.log(bz.age());//25
        console.log(bz.name);//Linda
        console.log(typeof bz);//object
2, boolean type No special property or method.
. 3, there are some static properties Number Type Number call directly, without the new operator
1) number of static properties:
 MAX_VALUE: maximum table
 MIN_VALUE: table minimum
       NaN: non-numerical table
 prototype: New properties and methods for increasing the
2) The method of the object number
      toString (): converts a string value
toLocaleString (): converts a string according to the local number format
       toFixed (): the number after the specified number of decimal places and converted to a string
4, String type
Properties 1) string object
     length: Returns the length of the string
constructor: function creates a String object is returned
  prototype: extended string is defined by the add properties and methods
2) Operation String
concat (str1 ... str2): a series string to the string parameter invoked the method (later superimposed)
slice (n, m): returns the string m n to a position between the string (argument is negative return all)
     substring (n, m): supra (directly to the second parameter is negative 0)
substr (n, m): Returns a string begins m n string
eg.
var str = "hello world";
console.log (str.substring (-1)); // hello world return all parameter is negative
3) The method of the position of the string
    indexOf (str, n): Start from the first search str n, and the index value of the search are returned
lastIndexOf (str, n): str n from the last to start the search, and returns search index
Note: If the specified string is not found or -1
4) compare two strings localeCompare (str1, str2)
 var str = "hello";
1. If the string of the alphabet to be ahead of the string parameter, the negative number (-1 majority)
 console.log(str.localeCompare("yellow"));//-1 
Explain: str2 they do not contain all h -1
       
2. If the string is equal to the string parameter returns 0
 console.log(str.localeCompare("hello"));//0
Explanation: str2 str1 congruent and only returns 0, including case
3. If the character string in the table should be behind a string, returns a positive number (the majority 1)
 console.log(str.localeCompare("eight"));//1
Explained: str2 contains just 1 h return
       

Guess you like

Origin www.cnblogs.com/LindaBlog/p/10984198.html