1.数组&字符串去重
/*var arr1 ="abcdabcd";*/var arr1=['a','b','c','a','d','b']var arr2=[];for(var i=0;i
2.判断数组是否存在重复值
var arr=['333','222','222','444','333'];var s=arr.join(",")+",";for(var i=0;i0) alert("数组中有重复元素:" + arr[i]);}
注:如果数组存在俩个以上相同的值容易产生存在异常。以及当数组是['333','222','222','444','3333'];会判断重复值有333,因此方法一存在一定的局限性, 没有达到通用
2.2判断数组是否存在重复值——(2)
var ary = new Array("111","22","33","111");var nary=ary.sort();for(var i=0;i
3.判断数组中是否有重复的内容,如果有,返回 true
否则,返回 false
function isRepeat(arr){ var hash = []; for(var i in arr) { if(hash[arr[i]]) return true; hash[arr[i]] = true;} return false;}var arr=["111","22","33","111"];alert(isRepeat(arr))
4.获取浏览器URL中查询字符串中的参数
测试:https://www.runoob.com/jsref/met-win-close.html?channelid=12333&name=xiaoming&age=23
function showWindowHref(arr){ var sHref = arr; var args = sHref.split('?'); if(args[0] == sHref){ return ""; } var arr = args[1].split('&'); alert(arr) //staffid=12333,name=xiaoming,age=23 var obj = {}; for(var i = 0;i< arr.length;i++){ var arg = arr[i].split('='); obj[arg[0]] = arg[1]; console.log(obj[arg[0]]) //12333,xiaomi,23 } return obj;}var href = showWindowHref("https://www.runoob.com/jsref/met-win-close.html?staffid=12333&name=xiaoming&age=23"); // objalert(href['name']); // xiaoming