var colors = ['red','color','yellow'];
var colors2 = new Array();
var arr = []; //經過下標進行一一賦值 arr[0] = 123; arr[1] = '哈哈哈'; arr[2] = '嘿嘿嘿'
var north = ['北京','山東','天津']; var south = ['東莞','深圳','上海']; var newCity = north.concat(south); console.log(newCity) //結果:["北京", "山東", "天津", "東莞", "深圳", "上海"]
var score = [98,78,76,100,0]; var str = score.join('|'); console.log(str);//98|78|76|100|0
var score = [98,78,76,100,0]; //toString() 直接轉換爲字符串 每一個元素之間使用逗號隔開 var str = score.toString(); console.log(str);//98,78,76,100,0
var arr = ['王力宏','周杰倫','張學友','林俊杰']; var newArr = arr.slice(1,3); console.log(newArr);//["周杰倫", "張學友"]
var arr = ['王力宏','周杰倫','張學友','林俊杰']; var newArr = arr.pop(); console.log(arr);//["王力宏", "周杰倫", "張學友"] console.log(newArr);//林俊杰
var arr = ['張三','李四','王文','趙六']; var newArr = arr.push('小馬哥'); console.log(newArr);//["張三", "李四","王文","趙六","小馬哥"]
var names = ['alex','xiaoma','tanhuang','angle']; //4.反轉數組 names.reverse(); console.log(names);
var names = ['alex','xiaoma','tanhuang','abngel']; names.sort(); console.log(names);// ["alex", "angle", "tanhuang", "xiaoma"]
布爾類型值 = Array.isArray(被檢測的值) ;
var str = '周杰倫'; var charset = str.charAt(1); console.log(charset);//傑
var str = '周杰倫' var str1 = '昆凌' console.log(str.concat(str,str1));//周杰倫周杰倫昆凌
var str = '周杰倫' var str1 = '昆凌' var str2 = str1.replace('昆凌','蔡依林') console.log(str2);//'蔡依林'
var str = 'alex'; console.log(str.indexOf('e'));//2 console.log(str.indexOf('p'));//-1
var str = '周杰倫'; console.log(str.slice(1,2));//傑
var str = '個人天呢,a是嘛,你在說什麼呢?a哈哈哈'; console.log(str.split('a'));//["個人天呢,", "是嘛,你在說什麼呢?", "哈哈哈"]
var str = '周杰倫喜歡昆凌,由於那是她老婆' var str2 = str.substr(3,6) console.log(str2);//'喜歡昆凌,因
var str = 'XIAOMAGE'; console.log(str.toLowerCase());//xiaomage
var str = 'xiaomage'; console.log(str.toUpperCase());
特別:javascript
//1.將number類型轉換成字符串類型 var num = 132.32522; var numStr = num.toString() console.log(typeof numStr) //四捨五入 var newNum = num.toFixed(2) console.log(newNum)
//建立了一個date對象 var myDate = new Date();
//建立日期對象 var myDate=new Date(); //獲取一個月中的某一天 console.log(myDate.getDate()); //返回本地時間 console.log(myDate().toLocalString());//2018/5/27 下午10:36:23
var x = 1.234; //天花板函數 表示大於等於 x,而且與它最接近的整數是2 var a = Math.ceil(x); console.log(a);//2
var x = 1.234; // 小於等於 x,而且與它最接近的整數 1 var b = Math.floor(x); console.log(b);//1
//求 兩個數的最大值 最小值 console.log(Math.max(2,5));//5 console.log(Math.min(2,5));//2
var ran = Math.random(); console.log(ran);[0,1)
min - max之間的隨機數: min+Math.random()*(max-min) ★★★★java