Javascript-Object <Script type = "text/javascript"> /* Introduce a new lightweight IDE for html, css, and javascript ---- Brakets (Baidu) In w3c standards, javascript is classified as an object-oriented programming language. However, the biggest feature of object orientation cannot be reflected in javascript. The OOP language enables us to define our own objects and variable types. Of course, although javascript does not fully reflect many characteristics of object-oriented language Other methods are used to make up --- The most common method for string objects ----- 1. charAt () returns the character at the specified position. 2. charCodeAt () returns the Unicode encoding of characters at the specified position 3. concat () connection string. 4. indexOf () to retrieve strings 5. lastIndexOf () searches for strings from the back and forward. 6. localCompare () compares two strings in a specific local order. 7. match () finds matching of one or more in-process expressions 8. replace () replaces the substring that matches the regular expression. 9. search () to retrieve the value that matches the Regular Expression 10. slice () extracts the string segment and returns the extracted part in the new string. 11. split () splits the string into a string array. 12. substr () extracts a specified number of characters in the string from the start index number. 13. substring () extract the character between two specified index numbers in the string. 14. tolocalLowerCase () converts the string to lowercase. 15. tolocalUpperCase () converts the string to uppercase. 16. toLowerCase () converts the string to lowercase. 17. toUpperCase () converts the string to uppercase. --- The most common method for string objects -----*/ // 1. charAt () Var str = "hello, world "; Document. write (str. charAt (1) +" "); // 2. charCodeAt () Document. write (str. charCodeAt (2) +" "); // 3. concat () Var str1 = "hello "; Var str2 = "world "; Var str3 = "felayman "; Document. write (str. concat (str1, str2, str3) +" "); // 4. indexOf () Document. write (str. indexOf ("hello") +" "); // 5. lastIndexOf () Document. write (str. lastIndexOf ('felayman ') +" "); // 6. localCompare () Var s1 = "hello1 "; Var s2 = "hello2 "; Document. write (s1.localeCompare (s2 )); // 7. match () Var s3 = "helloworld "; Document. write (s3.match ("world") +" "); // 8. replace () Var s4 = "hello, world "; Document. write (s4.replace ("world", "felayman") +" "); // 9. search () Document. write (s4.search ("world ")); // 10. slice () Document. write (s4.slice (2) +" "); // 11. split () Var s5 = "hello world felayman "; Document. write (s5.split ("") +" "); // Separated by Spaces Document. write (s5.split ("") +" "); // Splits the string into every character Var s6 = "hello-world-felayman "; Document. write (s5.split ("-") +" "); // Use-as the separator to separate // 12. substr () Var s7 = "felayman "; Document. write (s7.substr (1, 4) +" "); // 13. substring () Document. write (s7.substring (1, 5) +" "); // 14. toLowerCase () Var ss1 = "FELAY "; Document. write (ss1.toLowerCase () +" "); // 15. toUpperCase () Var ss2 = "felayman "; Document. write (ss2.toUpperCase ); /* --- The most common method for string objects -----*/ /*************** Three important attributes of string 1. The constuctor constructor attribute returns a reference to the array function that creates this object. 2. length String length 3. prototype allows you to add attributes and methods to an object ***********************/ Var obj = new Object (); If (obj. constructor = Object ){ // Alert ("obj is an object reference "); } Var arr = new Array (); If (arr. constructor = Array ){ // Alert ("arr is an array reference "); } Var ssss = new String ("helloman "); String. prototype. name = ''; Ssss. name = "string "; Alert (ssss. name); // name is an attribute of String. // This is also the String type attribute that developers often extend. Var o = { Name: "felayman ", Age: 23 }; Object. prototype. holobby = null; O. Hober = "basketball"; // This also adds attributes to object o, which is the same as the attributes of objects created in JSON format. Alert (o. name + o. age + o. age ); **************** ****************/ // New an object (Standard new Method) Var obj1 = new String ("hello "); // Alert (obj1); // the object is not displayed here. In many languages, strings are only a special object. // Json format Var obj2 = { Name: "felayman ", Age: 22 }; // Alert (obj2); // The object is displayed here. /* Developers gradually prefer the json format, because json is currently the most popular way to interact with data in the background. Here, I will first learn the common methods of simple string objects and then learn more in-depth javascript objects (many data are referred to as reference types) /* 1. Calculate the length of a string. I am very surprised that many languages now want to evaluate the length of a string. But why does jaavscript set it to a string? What about attributes? It is estimated that javascript developers want to reflect their own different ideas. */ Var str1 = new String ("felayman111111 "); // Alert (str1 ); // Locate the index position of a character in the specified string // Alert (str1.indexOf ('E ')); // Check whether a specified character exists in the string // Alert (str1.match ('E ')); // Replace a specified character or string in the string // Alert (str1.replace ('1', '2 ')); // Alert (str1.replace ("111111", "222222 ")); // Converts all specified strings to uppercase. // Alert (str1.toLocaleUpperCase ()); // Convert all specified strings to lowercase letters Var str2 = "FELAYMAN "; // Alert (str2.toLocaleLowerCase ()); // Retrieve the substring of the string // Alert (str1.substr (0, 4 )); // Alert (str1.substring (0, 4 )); // Split the string into an array Var str = "How are you doing today? " // Alert (str. split ("", 3 )); // Connection string Var s = str. concat (str1, str2 ); // Alert (s ); // Return the characters at the specified position. // Alert (str. charAt (1 )); // Returns the Unicode encoding of characters at the specified position. // Alert (str. charCodeAt (1 )); </Script> |