JS in Location.search, Split () HTML5 in Localstorage

Source: Internet
Author: User
Tags what array

1.location.search the method that gets the URL parameter on the client Location.search is a string starting from the current URL, such as: http://www.baidu.com/s?wd=baidu&cl= 3 Its search is? Wd=baidu&cl=3: Location.search.substr (1). Split ("&") [0] can return the first parameter: Wd=baidu such as: Location.search.split ('? ') [1] All parameters can be returned: the Wd=baidu&cl=3 2.split () method is used to split a string into a string array. Syntax Stringobject.split (separator,howmany) parameter description separator required. A string or regular expression that splits stringobject from where specified by the parameter. Howmany is optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length. Returns a string array of values. The array is created by splitting the string stringobject into substrings at the boundary specified by separator. The string in the returned array does not include the separator itself. However, if separator is a regular expression that contains a subexpression, the returned array includes the strings that match those sub-expressions (but not the text that matches the entire regular expression). Hints and Comment notes: If you use an empty string ("") as a separator, then each character in the Stringobject will be split. Note: The action performed by String.Split () is the opposite of what Array.join does. Example 1 in this example, we will split the string in different ways: Var str= "How is you doing today?" document.write (Str.split ("") + "
") document.write (Str.split (" ") +"
") document.write (Str.split (" ", 3))   output: How,are,you,doing,today? H,o,w,, A,r,e,, Y,o,u,, D,o,i,n,g,, T,o,d,a,y,? how,are,you Example 2 In this example, we will split the string with a more complex structure: "2:3:4:5". Split (":")//will return ["2", "3", "4", "5"] "|a|b|c". Split ("|")//will return ["", "a", " B "," C "] Example 3 using the following code, you can divide sentences into words: var words = Sentence.split (") or use regular expressions as separator:var words = Sentence.split (/\s+/) Example 4 If you want to divide the word into letters, or divide the string into characters, use the following code: "Hello". Split ("")//Can return ["H", "E", "L", "L", "O"] if only a subset of the characters need to be returned, use the Howmany parameter: "Hello" . Split ("", 3)//Can return ["H", "E", "L"]  3. HTML5 provided in the Localstorage object can save data for a long time on the client until the person is cleared. Localstorage provides several methods: 1, Storage: Localstorage.setitem (key,value) if key exists, update value 2, get: Localstorage.getitem (Key) If key does not exist return null 3, delete: Localstorage.removeitem (key) once deleted, key corresponding data will be deleted all  4, clear all: Localstorage.clear () Sometimes it is too cumbersome to use RemoveItem to delete each other, you can use clear, the result of the execution is to clear all the Localstorage object saved data  5, traverse localstorage stored key.length data total, Example: LocalStorage.length.key (index) Get key, example: Var key=localstorage.key (index),  6, storing JSON format data json.stringify  Converts an object into a JSON-formatted data string, returning the converted string Json.parse (data) to parse it into an object, returning the parsed object   Note: Localstorage data cannot be shared across browsers. A browser can only read data from its respective browser, with a storage space of 5M.

JS in Location.search, Split () HTML5 localstorage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.