jQuery data type summary of 14

  • 2020-11-26 18:42:54
  • OfStack

In addition to the built-in data types in the native JS (ES3en-ES4en datatype), jQuery also includes 1 extended data type (virtual types) such as Selectors, Events, and so on.

1. String

String is the most common and is supported in almost any high-level programming language and scripting language, such as "Hello world! That is, strings. The string is of type string. Such as

var typeOfStr = typeof "hello world"; / / typeOfStr for "string"

1.1 The String built-in method

"hello".charAt(0) // "h"
"hello".toUpperCase() // "HELLO"
"Hello".toLowerCase() // "hello"
"hello".replace(/e|o/g, "x") // "hxllx"
"1,2,3".split(",") // ["1", "2", "3"]

1.2 length property: returns the length of the character, such as "hello".length returns 5

1.3 String conversion to Boolean:

One empty string ("") defaults to false and one non-empty string to true (such as "hello").

2. Number

Number types, such as 3.1415926 or 1, 2, 3...

typeof 3.1415926 returns "number"

2.1 Convert Number to Boolean:

If an Number value is 0, the default is false; otherwise, true.

2.2 Since Number is implemented with double precision floating-point Numbers, the following situation is reasonable:

0.1 + 0.2 // 0.30000000000000004

3. Math

The following method is similar to the static method of the Math class in Java.

Math.PI // 3.141592653589793
Math.cos(Math.PI) // -1

3.1 Turn strings into Numbers: parseInt and parseFloat methods:

parseInt("123") = 123 (convert in decimal)
parseInt("010") = 8 (converts in base 8)
parseInt("0xCAFE") = 51966 (convert in base 106)
parseInt("010", 10) = 10 (specifies conversion in decimal)
parseInt("11", 2) = 3 (specifies conversion in base 2)
parseFloat("10.10") = 10.1

3.2 Numbers to strings

When Number is pasted onto the (append) string, the string is obtained.
"" + 1 + 2; // "12"
"" + (1 + 2); // "3"
"" + 0.0000001; // "1e-7"
Or cast:
String(1) + String(2); //"12"
String(1 + 2); //"3"

4. NaN and Infinity

If the parseInt method is called on a non-numeric string, NaN(Not a Number) is returned. NaN is often used to detect whether a variable is a numeric type, as follows:

isNaN(parseInt("hello", 10)) // true
Infinity means infinite or infinitesimal value, such as 1/0 // Infinity.

Calling the typeof operator on both NaN and Infinity returns "numuber".

Also NaN==NaN returns false, but Infinity==Infinity returns true.

5. Integer and Float

It's divided into representing integers and floating point.

6. BOOLEAN

Boolean, true or false.

7. OBJECT

1 in JavaScript is all objects. The typeof operation on an object returns "object".


var x = {}; 
var y = { name: "Pete", age: 15 };

For the y object above, you can use dots to get attribute values, such as y.name returns "Pete" and ES192en.age returns 15

7.1 Array Notation (array access method to access objects)


var operations = { increase: "++", decrease: "--" } 
var operation = "increase"; 
operations[operation] // "++"; 
operations["multiply"] = "*"; // "*"

The above operations [" multiply "] = '*'; An ES204en-ES205en pair is added to the operations object.

7.2 Cyclic object access: ES208en-in


var obj = { name: "Pete", age: 15}; 
for(key in obj) { 
alert("key is "+[key]+", value is "+obj[key]); 
}

7.3 true is the default for any object with or without properties and values

7.4 Prototype attribute for the object

jQuery Add object (function) to jQuery Instances dynamically using fn (alias for Prototype)


var form = $("#myform"); 
form.clearForm; // undefined 
form.fn.clearForm = function() {
return this.find(":input").each(function() { this.value = ""; }).end();
}; 
form.clearForm() // works for all instances of jQuery objects, because the new method was added

8. OPTIONS

Almost all jQuery plug-ins provide an API based on OPTIONS, which is an JS object, meaning that the object and its attributes are optional (optional). Allow customization.
For example, Ajax is used to submit the form,

$("#myform").ajaxForm(); // By default, Action attribute value of Form is used as ES246en-ES247en, and Method is used as submission type (GET/POST).
$("#myform").ajaxForm({ url: "mypage.php", type: "POST" }); // overrides the URL and the submission type to which the submission was made

9. ARRAY

var arr = [1, 2, 3];

So ARRAY is the variable lists. ARRAY is also an object.

Read or set the values of the elements in ARRAY in this manner:


var val = arr[0];//val for 1
arr[2] = 4;// now arr The first 3 An element is 4

9.1 Array loop (traversal)


for (var i = 0; i < a.length; i++) { // Do something with a[i] }
 But when it comes to performance, it's best to read only 1 time length Properties, as follows: 
for (var i = 0, j = a.length; i < j; i++) { // Do something with a[i] }
jQuery provides each Method Traversal group: 
var x = [1, 2, 3]; 
$.each(x, 
function(index, value) { 
console.log("index", index, "value", value); 
});

9.2 Calling the push method on an array means adding 1 element to the end of the array, such as x.push (5); And x [x length] = 5; equivalent

9.3 Other built-in methods of arrays:


var x = [0, 3, 1, 2]; 
x.reverse() // [2, 1, 3, 0] 
x.join("  �  ") // "2 - 1 - 3 - 0" 
x.pop() // [2, 1, 3] 
x.unshift(-1) // [-1, 2, 1, 3] 
x.shift() // [2, 1, 3] 
x.sort() // [1, 2, 3] 
x.splice(1, 2) //  Used to insert, delete, or replace array elements, in this case delete from index=1 The start of the 2 An element 

9.4 Arrays are objects, so always true

10. MAP


The map type is used by the AJAX function to hold the data of a request. This type could be a string, an array<form elements>, a jQuery object with form elements or an object with key/value pairs. In the last case, it is possible to assign multiple values to one key by assigning an array. As below:
{'key[]':['valuea','valueb']}

11. FUNCTION: Anonymous and named

11.1 Context, Call and Apply


In JavaScript, the variable "this" always refers to the current context. 
$(document).ready(function() { 
// this refers to window.document}); 
$("a").click(function() { // this refers to an anchor DOM element
});

12. SELECTOR

There are lot of plugins that leverage jQuery's selectors in other ways. The validation plugin accepts a selector to specify a dependency, whether an input is required or not:
emailrules: { required: "#email:filled" }
This would make a checkbox with name "emailrules" required only if the user entered an email address in the email field, selected via its id, filtered via a custom selector ":filled" that the validation plugin provides.

13. EVENT

DOM standard events include: blur, focus, load, resize, scroll, unload, beforeunload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, andkeyup

14. JQUERY

The JQUERY object contains a collection of DOM elements. For example, $('p') returns all < p > ... < /p >
The JQUERY object behaves like an array, has the length attribute, and can also access one of the DOM elements collection through index. But it's not an array, it doesn't have some of the methods of an array, like join().

Many jQuery methods return the jQuery object itself, so you can use a chained call:
$("p").css("color", "red").find(".special").css("color", "green");
But if you call a method that breaks an jQuery object, such as find() and filter(), it doesn't return the original object. To return to the original object, you simply call the end() method again.


Related articles: