Get a random number of 0-9:
Math.Round (Math.random () *9);
To remove duplicate elements from an array:
var arr=[1,3,5,4,3,3,1,4]function editarr (arr) {var result=[];for (var i=0; i<arr.length; i++) { if ( Result.indexof (arr[i]) = =-1) { Result.push (arr[i]);} } Console.log (result);} Editarr (arr);
The + function parsequery is used to parse URL query parameters .
-The syntax is as follows:
-var obj = parsequery (query)
-query is the parsed query parameter, and the function returns the parsed object.
-Use the following example:
-var Jerry = Parsequery ("name=jerry&age=1");
-jerry; Return value: {name: "Jerry", Age: "1"}
-var Tom = Parsequery ("Name= Tom &age=12&gender&");
-tom; Return value: {name: "Tom", Age: "" ", Gender:"}
-Please write out the implementation code of the function Parsequery.
Method One:
function Parsequery (query) {var arr = query.replace (/\s+/g, "). Split (' & '); var obj = {};for (var i = 0; i < arr.length ; i++) {if (Arr[i]) {var newArr = arr[i].split (' = '), if (!newarr[1]) {newarr[1] = ';} Obj[newarr[0]] = newarr[1];}} return obj;}
Method Two:
function Parsequery (query) {var reg =/([^=&\s]+) [=\s]* ([^=&\s]*)/g;var obj = {};while (reg.exec (query)) { OBJ[REGEXP.$1] = regexp.$2;} return obj;}
"Front End Learning Notes" JavaScript small case Collection