JS Array console sequencing

Source: Internet
Author: User

The recent beginner JS, think is a very powerful language, early in the console output, a simple summary of the method of array sorting:

First, select the sort and then go to weight:

Let arr = [3,7,2,9,6,5,8,7,3];let temp;for (Let i=0; i<arr.length-1; i++) {for    (let J=i+1; j<arr.length; j + +) {
   if (Arr[i]>arr[j]) {            temp = arr[i];            Arr[i] = arr[j];            ARR[J] = temp;}}    } Let arr1 = [];for (let k=0; k<arr.length; k++) {    if (arr[k]! = arr[k+1]) {        arr1 = Arr1.concat (Arr[k]);}    } Console.log (ARR1);

This method is more complex, and the order of the array to be re-ordered will change, so it is only a reference to a thought exercise:

Second, the direct removal of repeated element method to weight:

Let arr = [3,7,2,3,9,6,7,5,8,7];for, let i=0; i<arr.length; i++] {for    (let J=i+1; j<arr.length; j + +) {        if (AR R[i]==arr[j]) {             arr.splice (j,1);}}    Console.log (arr);


JS Array console sequencing

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.