Premise: The element type in the array is: string
Read on the Internet a lot of tall still articles, or can not solve my string arry problem, only blame their brains, on the code:
<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <title>JQ array string de-weight</title> <Scriptsrc= "Jquery-1.7.2.min.js"></Script> <Scripttype= "Text/javascript"> $(function () { varSbarray= NewArray (["Beijing"], ["Shijiazhuang"], ["Tianjin"], ["Beijing"], ["Shijiazhuang"], ["Tianjin"], ["Baoding"], ["Beijing"], ["Handan"], ["Baoding"], ["Langfang"], ["Baoding"]); varSB= NewArray (); alert (sbarray.length); Alert (Sbarray.indexof ("Beijing")); //iterating through an array $('input'). Click (function () { if(Sbarray.length> 0) { for (varI= 0; I<sbarray.length; I++) { if(Sb.tostring (). IndexOf (Sbarray[i])< 0) {Sb.push (sbarray[i]); } }//End for $("#p2"). Text (sb.tostring ()); }//End If }); }); </Script></Head><Body> <inputtype= "button"value= "Row Weight" /> <PID= "P2"></P></Body></HTML>
Note: In the Sbarray array, the return value of Sbarray.indexof ("Beijing") is-1, which is not included, and it does not appear to be directly judged by the indexOf ().
In order to achieve the effect, a ToString () method was added to convert the indexof () board to a string after it was forced to use.
This is my own thinking of the stupid method, of course, its time complexity may not meet the requirements of everyone, do not spray.