Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array

后端 未结 30 3119
再見小時候
再見小時候 2020-11-21 04:35

I need to check a JavaScript array to see if there are any duplicate values. What\'s the easiest way to do this? I just need to find what the duplicated values are - I don\'

30条回答
  •  囚心锁ツ
    2020-11-21 05:32

    Here is a very light and easy way:

    var codes = dc_1.split(',');
    var i = codes.length;
    while (i--) {
      if (codes.indexOf(codes[i]) != i) {
        codes.splice(i,1);
      }
    }
    

提交回复
热议问题