js list去重复

var dataList = [];//需要去重复的集合
var res = [];//去重复后的集合
var tem = {};
  for(var i = 0; i < dataList.length; i++){
	 if(!json[dataList[i]]){
		 res.push(dataList[i]);
		  tem[dataList[i]] = 1;
	 }
}

  

原文地址:https://www.cnblogs.com/ywx2/p/10960390.html

时间: 2024-11-03 09:25:58

js list去重复的相关文章

js 数组去重复、内置方法

1.使用js 数组去重复: 方法①: var arr=[1,2,1,5,2,3,5,1,6,9]; function deRepeat(){ var newArray=[]; var obj={}; var index=0; var len=arr.length; for(var i=0;i<len;i++){ if(obj[arr[i]]==undefined){//不存在 obj[arr[i]]=1; newArray[index++]=arr[i]; }else if(obj[arr[i]

Js数组去重复取唯一值

function isBigEnough(element) { return element >= 10; } var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); // filtered is [12, 130, 44] function onlyUnique(value, index, self) { return self.indexOf(value) === index; } // usage example: var a = [

js 数组去重复

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript"> window.onload = function (){ var arr = [11,13,22,11,5,13,7]; fun

js 数组去重复键

Array.prototype.deleteEle = function() { var newArr = this; for (var i = newArr.length - 1; i >= 0; i--) { var targetNode = newArr[i]; for (var j = 0; j < i; j++) { if (targetNode == newArr[j]) { newArr.splice(i, 1); break; } } } return newArr; } 调用

js 数组去重复两种方法一看就懂

var arr=[1,1,2,2,3,5,2];function uniqueArr(arr){ var data=[]; for(var i=0;i<arr.length;i++){ if(data.indexOf(arr[i])<0){ data.push(arr[i]); } } return data;}console.log(uniqueArr(arr));var arr1=[1,2,2,5,5,4,5,6,3,36,52];function uniquearr(arr){ var

js数组和字符串去重复几种方法

js数组去重复几种方法 第一种:也是最笨的吧. Array.prototype.unique1 = function () { var r = new Array(); label:for(var i = 0, n = this.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x] == this[i]) { continue label; } } r[r.length] = this[i]; } re

js数组操作 求最大值,最小值,正序、倒叙大小值排序,去重复

var arr = [1,5,2,56,12,34,21,3,5] Math.min.apply({},arr) // 1 Math.max.apply({},arr) // 56 arr.sort((m,n)=>m-n) // [1, 2, 3, 5, 5, 12, 21, 34, 56] arr.sort((m,n)=>n-m) //[56, 34, 21, 12, 5, 5, 3, 2, 1] 去重复 var arr = [2,1,4,3,2,4,2,3,4,2,6,5,5] var o

高效率去掉js数组中重复项

Array类型并没有提供去重复的方法,如果要把数组的重复元素干掉,那得自己想办法: 1 function unique(arr) { 2 var result = [], isRepeated; 3 for (var i = 0, len = arr.length; i < len; i++) { 4 isRepeated = false; 5 for (var j = 0, len = result.length; j < len; j++) { 6 if (arr[i] == result

C# List&lt;T&gt;中Select List Distinct()去重复

List<ModelJD> data = myDalJD.GetAllDataList(); List<string> list= new List<string>(); list= datalist4.Select(p => p.name).ToList(); //只取name字段,重新生成新的List集合 this.cmbJdUserName.DataSource = list.Distinct().ToList(); //去重复,绑定数据后面要加ToList