Remove repeated data from the array

06

  Why write the maximum and maximum length minus one here, because k starts from 0. For t.length starts from 1, the length starts from 1. That's it.

    One thing that must be clear is that i = 0, i <array.length, i ++. Perform length loops, which means that the loop body enters the loop body for length loops, and jumps out of the loop when I equals length.

  Just follow the process strictly once and you will know

  Write directly in JS, you can see it by clicking Run

  It can also be done in a deleted way.

  The idea is to compare one with the next, delete yourself if there are duplicates, and then compare again,

  Every time I have to go back to -1, right, there are some problems, for a while

var arr = [1,1,3,34,3,2,5,5,5,61]

 

for (var i = 0; i < arr.length-1; i++) {

    

    for (var j = 0; j < arr.length-1; j++) {

        if (arr[i]==arr[j+1]) {

            arr = arr.splice(i,1)

            i=-1

            break

        }else{

            continue

        }

        

    }

}

console.log(arr);

Published 11 original articles · praised 0 · visits 244

Guess you like

Origin blog.csdn.net/Douglas_Ryan_/article/details/105241128