<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
(function() {
// concat() 连接两个或更多的数组,并返回结果。
// let arr1 = [1, 2, 3, 4, 5];
// let arr2 = [5, 4, 3, 2, 1];
// let arr3 = arr1.concat(arr2);
// console.log('arr3', arr3);
// let arr1 = '1212';
// let arr2 = '665';
// let arr3 = arr1.concat(arr2);
// console.log('arr3', arr3);//1212665
//copyWithin() 从数组的指定位置拷贝元素到数组的另一个指定位置中。(会改变原来的数组结构)
// var fruits = ["Banana", "Orange", "Apple", "Mango", "Mango1"];
// var fruits2 = fruits.copyWithin(2, 0);
// console.log(fruits, fruits2);
//fruits "Banana", "Orange", "Banana", "Orange", "Apple"
//fruits2 "Banana", "Orange", "Banana", "Orange", "Apple"
// fruits2.splice(2, 1);
//fruits "Banana", "Orange", "Orange", "Apple"
// entries() 返回数组的可迭代对象。
// var fruits3 = ["Banana", "Orange", "Apple", "Mango"];
// let x = fruits3.entries();
// console.log('entries1', x.next().value); //0, "Banana"
// console.log('entries2', x.next().value); //1, "Orange"
// every() 检测数值元素的每个元素是否都符合条件。最终返回结果为boolean
// var arr = [1, 2, 3, 5];
// var arr2 = arr.every(function(item) {
// return item <= 5;
// })
// console.log('arr2', arr2);
// fill() 使用固定值填充数组
// var arr = new Array(3);
// arr.fill(0);
// console.log('arr', arr);
// filter() 检测数值元素,并返回符合条件所有元素的数组。
// var arr = [1, 2, 3, 5];
// var arr2 = arr.filter(function(item) {
// return item < 5;
// })
// console.log('arr', arr);
// console.log('arr2', arr2);
//去重
// var arr = [1, 2, 3, 2, 3, 5];
// var arr2 = arr.filter(function(item, index, thisarr) {
// //thisarr.indexOf(item, 0) 获取item在原数组的位置,0表示从索引0开始检查数组
// //判断item在原始数组中第一次出现的位置与当前遍历到的索引位置是否一致,不一致则为重复
// return thisarr.indexOf(item, 0) === index;
// })
// console.log('arr', arr);
// console.log('arr2', arr2);
let a = '';
let a1 = 1;
let a2 = {};
let a3 = [];
let a4 = true;
let a5 = function() {};
let a6 = undefined;
let a7 = null;
// console.log('typeof a', typeof a) //string
// console.log('typeof a1', typeof a1) //number
// console.log('typeof a2', typeof a2) //object
// console.log('typeof a3', typeof a3) //object
// console.log('typeof a4', typeof a4) //boolean
// console.log('typeof a5', typeof a5) //function
// console.log('typeof a6', typeof a6) //undefined
// console.log('typeof a7', typeof a7); //object
//instanceof 只适合对象类型,不适合基本数据类型
// console.log('a instanceof String', a instanceof String); //false
// console.log('a1 instanceof Number', a1 instanceof Number); //false
// console.log('a2 instanceof Object', a2 instanceof Object); //true
// console.log('a3 instanceof Object', a3 instanceof Object); //true
// console.log('a3 instanceof Array', a3 instanceof Array); //true
// console.log('a4 instanceof Boolean', a4 instanceof Boolean); //false
// console.log('a5 instanceof Function', a5 instanceof Function); //true
// console.log('a6 instanceof undefined', a6 instanceof Object); //false
// console.log('a7 instanceof Object', a7 instanceof Object); //false
//判断是否是数组使用 constructor 比较准确
// console.log('a.constructor == String', a.constructor == String); //true
// console.log('a1.constructor == Number', a1.constructor == Number); //true
// console.log('a2.constructor == Object', a2.constructor == Object); //true
// console.log('a3.constructor == Array', a3.constructor == Array); //true
// console.log('a3.constructor == Object', a3.constructor == Object); //false
// console.log('a4.constructor == Boolean', a4.constructor == Boolean); //true
// console.log('a5.constructor == Function', a5.constructor == Function); //true
// console.log('a6.constructor == undefined', a6.constructor == Object); //a6.constructor 报错没有constructor属性
// console.log('a7.constructor == Object', a7.constructor == Object); //a7.constructor 报错没有constructor属性
//Object.prototype.toString.call 判断所有类型都比较准确
console.log('a is', Object.prototype.toString.call(a)); //[object String]
console.log('a1 is', Object.prototype.toString.call(a1)); //[object Number]
console.log('a2 is', Object.prototype.toString.call(a2)); //[object Object]
console.log('a3 is', Object.prototype.toString.call(a3)); //[object Array]
console.log('a4 is', Object.prototype.toString.call(a4)); //[object Boolean]
console.log('a5 is', Object.prototype.toString.call(a5)); //[object Function]
console.log('a6 is', Object.prototype.toString.call(a6)); //[object Undefined]
console.log('a7 is', Object.prototype.toString.call(a7)); //[object Null]
})()
</script>
</html>
|