JS & Jquery base and an array of objects and the type of conversion

A, braces {}, the definition of an object represents, in most cases have pairs of attributes and values, or function.

Such as: var LangShen = { "Name" : "Langshen", "AGE": "28"};

above declares called & ldquo; LangShen & rdquo; object, a plurality of attribute or function by, (comma), because it is a property of the object,

so access should be used (point) to access the layers:. LangShen.Name, LangShen.AGE, of course, we can also use an array of ways to access, such as: LangShen [ "Name"], LangShen [ "AGE"], the result is the same.

The wording JSON often used in the data structure, in addition, when we usually write function group, are often used, such as:

var = {LangShen
       the Name = function () {
                  return "LangShen";
                   },

      Age = function () {
                 return "28";
                 }

}

almost call mode, because the group is a function of, so to add (), such as: alert (LangShen.Name ());

two, [] brackets, represents an array, and It can be understood as an array object.

Such as: var LangShen = [ "Name" , "

Obviously, each value or function, are independent, only between a plurality of values, (comma), because the object is an array, it is equal to:

var = LangShen the Array ( "the Name", "LangShen", "AGE", "28") ;

access, and the array is the same, alert (LangShen [0]) ;

three, used with {} [], as we said, is an object {}, [] is a array, we can be composed of an array of objects, such as:

var LangShen = { "the Name": "Langshen",
                           "Mywife": [ "LuLu", "26 is"],
                           "MySoN": [{ "the Name": "SON1" }, { "the Name": "Son2"}, { "the Name": "Son3"}]
}

from the above structure, the first item is an object which is the attribute, the second term is an array, the third comprising an array of a plurality of objects. Calling up, layer by layer is accessed, the object's properties with. (Dot) is superimposed, with the array [index] to access

 

1. The transfer function:

JS Providing the parseInt () and parseFloat () two conversion functions. The former value into an integer, which converts into a floating point value. Only call these methods String type, these two functions to run correctly; for other types of returns are NaN (Not a Number).

In determining whether the value of the string before the number is, parseInt () and parseFloat () will carefully analyze the string. the parseInt () method first check character position 0, it is determined whether or not it is a valid number; if not, the method returns NaN, does not continue to perform other operations. But if the character is a valid number, which will look at the character in the position 1, the same test. This process continues until it reaches the non-active character figures, at this time the parseInt () will convert the character string into digital before.

2. The cast

may also be used casts (type casting) process type conversion value. Use Casts may access a specific value, even if it is another type.
ECMAScript can be used in three types of cast follows:
Boolean (value) - the given values into Boolean type;
Number The (value) - the given value into a digital (either integer or floating point);
string (value) - the given value into a string.
A conversion value of one of these three functions, will create a new value, for translation from the original value directly into the value. This will result in unintended consequences.
When the value is converted to at least one character string, or an object other than 0 (this is discussed in the next section) is, Boolean () function returns true. If the value is an empty string, number 0, undefined, or null, it returns false.


Guess you like

Origin www.cnblogs.com/hualiuliu/p/11453693.html