The de-weight of the array, and a random verification code

Source: Internet
Author: User

The de-weight of an array

The code is as follows:

  var arr=[1,1,1,12,2,3,4,4,5];  
function Quchong (arrtest) {
var Arrkong=[]; var an empty array that stores the content that is not duplicated
for (Var i=0;i<=arrtest.length;i++) {// Iterate through each element in the array
if (Arrkong.indexof (Arrtest[i]) <0) {//will not duplicate elements, i.e. indexOf The number of <0 is removed
Arrkong.push (Arrtest[i]); Use the push method to place the non-repeating elements into the new array
"

return arrkong;//return value is new array

}

document.write (Quchong (arr)); The result is 1.12,2,3,4,5



II production random verification code


var str1= ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-_ '; Determine the scope of the Verification code
function Suiji (n) {
var str= '; var an empty string that stores randomly generated characters
for (Var i=0;i<n;i++) { //number of characters required, loop
var Num=math.floor (Math.random () *str1.length); Random string angle Index by random number method
Str+=str1.substring (num,num+1); The resulting string is mapped to the contents of the string and stored in a new string of the previous Var
} return str; Returns a new string
}
Console.log (Suiji (5));



The de-weight of the array, and a random verification code

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.