在ES5的时候,js数据类型有6种:Number、String、Boolean、undefined、object、Null。
注:https://blog.csdn.net/u013592575/article/details/95087953
一、js判断类型
Object.prototype.toString可以看出一个值到底是什么类型。
Object.prototype.toString.call(2) // "[object Number]"
Object.prototype.toString.call('') // "[object String]"
Object.prototype.toString.call(true) // "[object Boolean]"
Object.prototype.toString.call(undefined) // "[object Undefined]"
Object.prototype.toString.call(null) // "[object Null]"
Object.prototype.toString.call(Math) // "[object Math]"
Object.prototype.toString.call({}) // "[object Object]"
Object.prototype.toString.call([]) // "[object Array]"
注:https://segmentfault.com/a/1190000013243913
二、数组函数
https://www.jianshu.com/p/66b04163948b
https://juejin.im/post/5b0903b26fb9a07a9d70c7e0
三、函数返回数组
function createFunction(){
var result = new Array();
for (var i = 0; i < 10; i++) {
result.push(i)
}
return result;
}
console.log(createFunction());
http://www.imooc.com/wenda/detail/464877
四、数组元素的字符串化
join()方法是一个非常实用的方法,它把当前Array的每个元素都用指定的字符串连接起来,然后返回连接后的字符串
arrayObj.join(separator); //返回字符串,这个字符串将数组的每一个元素值连接在一起,中间用 separator 隔开。
var arr = ['A', 'B', 'C', 1, 2, 3];
arr.join('-'); // 'A-B-C-1-2-3'
https://www.jianshu.com/p/66b04163948b
五、js取json对象的键和值
//构建一个json对象
var jb={"美的":49,"三星":35,"海信":25,"格力":16,"方太":14};
for(var key in jb){
alert(key); //json对象的key
alert(jb[key]); //json对象的值
}
https://www.cnblogs.com/jpfss/p/9687128.html
六、js数组去重
function unique (arr) {
return Array.from(new Set(arr))
}
var arr = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique(arr));
https://segmentfault.com/a/1190000016418021?utm_source=tag-newest
七、$.each()是对数组的遍历
var arr1=['aa','bb','cc','dd'];
$.each(arr1,function(i,val){ //两个参数,第一个参数表示遍历的数组的下标,第二个参数表示下标对应的值
console.log(i+'```````'+val);
});