个人总结

1.数租去重

	<script>
		var arr1 = [1, 2, 2, 2, 3, 3, 3, 4, 5, 6],
			arr2 = [];
		for(var i = 0, len = arr1.length; i < len; i++) {
			if(arr2.indexOf(arr1[i]) < 0) {
				arr2.push(arr1[i]);
			}
		}
		document.write(arr2)
	</script>

2.数组排序

	<script>
		var array = [1, 4, -8, -3, 6, 12, 9, 8];
		//排序函数
		function compare(val1, val2) {
			return val1 - val2;
		};
		array.sort(compare);
		document.write(array);
	</script>

3.数组字符串的转换

	<script>
		//数组转字符串
		var a, b;
		a = new Array(0, 1, 2, 3, 4);
		b = a.join("-"); //"0-1-2-3-4"
		//字符串转数组
		var s = "abc,abcd,aaa";
		ss = s.split(","); // 在每个逗号(,)处进行分解  ["abc", "abcd", "aaa"]
		var s1 = "helloworld";
		ss1 = s1.split(''); //["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
	</script>

4.浏览器内核

	<div>
		<p>IE: trident内核 </p>
		<p>Firefox:gecko内核 </p>
		<p>Safari:webkit内核 </p>
		<p>Opera:以前是presto内核,Opera现已改用Google Chrome的Blink内核 </p>
		<p>Chrome:Blink(基于webkit,Google与Opera Software共同开发)</p>
	</div>

5.获取当前日期

	今天是:
	<script type="text/javascript">
		var d, s = "";
		var x = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
		d = new Date();
		s += d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日 ";
		s += x[d.getDay()];
		document.writeln(s);
	</script>
posted @ 2018-08-01 16:37  blue星期天  阅读(162)  评论(0编辑  收藏  举报