javascript的數(shù)組方法大全
在日常開發(fā)中,我們會(huì)接觸到j(luò)s中數(shù)組的一些方法,這些方法對(duì)我們來說,可以很遍歷的達(dá)到我們想要的結(jié)果,但是因?yàn)榉椒ū容^多,有些方法也不常用,可能會(huì)過一段時(shí)間就會(huì)忘記,那么在這里我整理了21個(gè)數(shù)組的方法,供大家查閱。
1:concat();
功能:合并數(shù)組,可以合并一個(gè)或多個(gè)數(shù)組,會(huì)返回合并數(shù)組之后的數(shù)據(jù),不會(huì)改變?cè)瓉淼臄?shù)組;
var str1 = [12,2,"hello"];var str2 = ["world"]; console.log(str1.concat(str2)); //[12, 2, "hello", "world"] console.log(str1); //[12,2,"hello"];
也可以使用es6的擴(kuò)展運(yùn)算符,不會(huì)改變?cè)瓟?shù)組
let str3 = [...str1,...str2]
2:join();
功能:將數(shù)組轉(zhuǎn)為字符串并返回轉(zhuǎn)化的字符串?dāng)?shù)據(jù),不會(huì)改變?cè)瓉淼臄?shù)組;
注意:()中用雙引號(hào)包括自己想用的分隔符,默認(rèn)為逗號(hào),這里方便觀察,我用了-
var str1 = [12,2,"hello"]; var str2 = ["world"]; console.log(str1.join("-")); //12-2-hello console.log(str1); //[12, 2, "hello"]
3:pop();
功能:刪除數(shù)組的最后一位,并且返回刪除的數(shù)據(jù),會(huì)改變?cè)瓉淼臄?shù)組
var str1 = [12,2,"hello"];console.log(str1.pop() //helloconsole.log(str1); //[12, 2]var str1 = [12,2,"hello"]; console.log(str1.pop() //hello console.log(str1); //[12, 2]
4:shift();
功能:刪除數(shù)組的第一位數(shù)據(jù),并且返回新數(shù)組的長(zhǎng)度,會(huì)改變?cè)瓉淼臄?shù)組
var str1 = [12,2,"hello"]; console.log(str1.shift()); //12 console.log(str1); //[2,"hello"]
5:unshift();
功能:在數(shù)組的首位新增一個(gè)或多數(shù)據(jù),并且返回新數(shù)組的長(zhǎng)度,會(huì)改變?cè)瓉淼臄?shù)組
注意:unshift()方法返回的數(shù)據(jù)是新數(shù)組的長(zhǎng)度,它增加的數(shù)據(jù)可以是一個(gè)也可以是多個(gè),可以理解為增加一連串的數(shù)據(jù),
var str1 = [12,2,"hello"]; var str2 = [43,2,"test"]; console.log(str1.unshift("你好")); //4 console.log(str2.unshift("hello","world")); //5 console.log(str1); //["你好", 12, 2, "hello"] console.log(str2);
6:push();
功能:在數(shù)組的最后一位新增一個(gè)或多個(gè)數(shù)據(jù),并且返回新數(shù)組的長(zhǎng)度,會(huì)改變?cè)瓉淼臄?shù)組
注意:push()方法返回的是數(shù)據(jù)是新數(shù)組的長(zhǎng)度,它增加的數(shù)據(jù)可以是一個(gè)也可以是多個(gè),可以理解為增加一連串的數(shù)據(jù)
var str1 = [12,2,"hello"]; var str2 = [43,2,"test"]; console.log(str1.push("你好")); //4 console.log(str2.push("hello","world")); //5 console.log(str1); //[12, 2, "hello","你好"] console.log(str2); //[43, 2, "test","hello", "world"]
7:reverse();
功能:將數(shù)組的數(shù)據(jù)進(jìn)行反轉(zhuǎn),并且返回反轉(zhuǎn)后的數(shù)組,會(huì)改變?cè)瓟?shù)組
var str1 = [12,2,"hello"]; console.log(str1.reverse()); //["hello", 2, 12] console.log(str1); //["hello", 2, 12]
8:sort();
功能:對(duì)數(shù)組內(nèi)的數(shù)據(jù)進(jìn)行排序(默認(rèn)為升序),并且返回排過序的新數(shù)組,會(huì)改變?cè)瓉淼臄?shù)組
注意:
8.1:
這里的排序是針對(duì)字符的排序,先使用數(shù)組的toString()方法轉(zhuǎn)為字符串,再逐位比較,3是大于12的,因?yàn)槭孜?>1,不要與Number型的數(shù)據(jù)排序混淆
8.2:
str2數(shù)組中增加了三個(gè)字符,可以看到,比較的時(shí)候,zoom是最大的,因?yàn)槭孜坏挠⑽淖帜竿ㄟ^ASCII碼可以轉(zhuǎn)為相應(yīng)的數(shù)值,再根據(jù)數(shù)值比較
var str1 = [12,2,43,5,2,5]; var str2 = [92,2,43,"hello",5,2,5,"abc","zoom"]; console.log(str1.sort()); //[12, 2, 2, 43, 5, 5] console.log(str1); //[12, 2, 2, 43, 5, 5] console.log(str2.sort()); //[2, 2, 43, 5, 5, 92, "abc", "hello", "zoom"] console.log(str2); //[2, 2, 43, 5, 5, 92, "abc", "hello", "zoom"]
8.3:排序問題
參數(shù):sort(callback) 如果需要按照數(shù)值排序,需要傳參。sort(callback),callback為回調(diào)函數(shù),該函數(shù)應(yīng)該具有兩個(gè)參數(shù),比較這兩個(gè)參數(shù),然后返回一個(gè)用于說明這兩個(gè)值的相對(duì)順序的數(shù)字(a-b)。其返回值如下:
若 a 小于 b,返回一個(gè)小于 0 的值。
若 a 等于 b,則返回 0。
若 a 大于 b,則返回一個(gè)大于 0 的值。
var str3 = [92,2,43,5,2,5]; console.log(str3.sort(fn)); //[2, 2, 5, 5, 43, 92] console.log(str3); //[2, 2, 5, 5, 43, 92] function fn (a,b){ return a-b; }
9:slice();
功能:截取指定位置的數(shù)組,并且返回截取的數(shù)組,不會(huì)改變?cè)瓟?shù)組
參數(shù):slice(startIndex, endIndex)
注意:可從已有的數(shù)組中返回選定的元素。該方法接收兩個(gè)參數(shù)slice(start,end),strat為必選,表示從第幾位開始;end為可選,表示到第幾位結(jié)束(不包含end位),省略表示到最后一位;start和end都可以為負(fù)數(shù),負(fù)數(shù)時(shí)表示從最后一位開始算起,如-1表示最后一位。
var arr = ["T1","J1","L1","L2","M1"]; console.log(arr.slice(1,3)); //["J1","L1"] console.log(arr.slice(1)); //["J1","L1","L2","M1"] console.log(arr.slice(-4,-1)); //["J1","L1","L2"] console.log(arr.slice(-2)); //["Lily","M1"] console.log(arr.slice(1,-2)); //["J1","L1"] console.log(arr); //["T1","J1","L1","L2","M1"]
10:splice()
功能:向數(shù)組中添加,或從數(shù)組刪除,或替換數(shù)組中的元素,然后返回被刪除/替換的元素。
參數(shù):splice(start,num,data1,data2,…); 所有參數(shù)全部可選。第一個(gè)參數(shù)是小標(biāo),第二個(gè)是刪除的長(zhǎng)度,第一個(gè)參數(shù)可以為負(fù)數(shù)
var list = [1, 2, 3] console.log(list); // [1, 2, 3] // 刪除 list.splice(0,1); // 刪除 -> 從下標(biāo)為0開始,長(zhǎng)度為1 console.log(list); // [2,3] list.splice(0,2); // 刪除 -> 從下標(biāo)為0開始,長(zhǎng)度為2 console.log(list); // [] //替換 list.splice(0,1,4); // 替換 -> 從下標(biāo)為0開始,長(zhǎng)度為1的數(shù)組元素替換成4 console.log(list); // [4,2,3] list.splice(0,2,4); // 替換 -> 從下標(biāo)為0開始,長(zhǎng)度為2的數(shù)組元素替換成4(即4,2整體替換成4) console.log(list); // [4,3] //添加 list.splice(1,0,5); // 表示在下標(biāo)為1處添加一項(xiàng)5 console.log(list); // [1,5,2,3]
如果第一個(gè)參數(shù)為負(fù)數(shù)就從后面往前數(shù),入上圖
splice會(huì)改變?cè)瓟?shù)組
11:toString();
功能:將數(shù)組轉(zhuǎn)換成字符串,類似于沒有參數(shù)的join()。該方法會(huì)在數(shù)據(jù)發(fā)生隱式類型轉(zhuǎn)換時(shí)被自動(dòng)調(diào)用,如果手動(dòng)調(diào)用,就是直接轉(zhuǎn)為字符串。不會(huì)改變?cè)瓟?shù)組
var str = [1,2,3]; console.log(str.toString()); //1,2,3 console.log(str); //[1,2,3]
12:valueOf();
功能:返回?cái)?shù)組的原始值(一般情況下其實(shí)就是數(shù)組自身),一般由js在后臺(tái)調(diào)用,并不顯式的出現(xiàn)在代碼中
var str = [1,2,3];console.log(str.valueOf()); //[1,2,3]console.log(str); //[1,2,3]//為了證明返回的是數(shù)組自身console.log(str.valueOf() == str); //true
13:IndexOf();
功能:根據(jù)指定的數(shù)據(jù),從左向右,查詢?cè)跀?shù)組中出現(xiàn)的位置,如果不存在指定的數(shù)據(jù),返回-1,找到了指定的數(shù)據(jù)返回該數(shù)據(jù)的索引
參數(shù):indexOf(value, start);value為要查詢的數(shù)據(jù);start為可選,表示開始查詢的位置,當(dāng)start為負(fù)數(shù)時(shí),從數(shù)組的尾部向前數(shù);如果查詢不到value的存在,則方法返回-1
注意:如果找到該數(shù)據(jù),立即返回該數(shù)據(jù)的索引,不再往后繼續(xù)查找
var str = ["h","e","l","l","o"]; console.log(str.indexOf("l")); //2 console.log(str.indexOf("l",3)); //3 console.log(str.indexOf("l",4)); //-1 console.log(str.indexOf("l",-1)); //-1 console.log(str.indexOf("l",-3)); //2
14:lastIndexOf();
功能:根據(jù)指定的數(shù)據(jù),從左向右,lastIndexOf() 方法可返回一個(gè)指定的元素在數(shù)組中最后出現(xiàn)的位置,從該字符串的后面向前查找。如果不存在指定的數(shù)據(jù),返回-1,找到了指定的數(shù)據(jù)返回該數(shù)據(jù)的索引
參數(shù):indexOf(value, start);value為要查詢的數(shù)據(jù);start為可選,表示開始查詢的位置,當(dāng)start為負(fù)數(shù)時(shí),從數(shù)組的尾部向前數(shù);如果查詢不到value的存在,則方法返回-1
var str = ["h","e","l","l","o"]; console.log(str.lastIndexOf("l")); //3
根據(jù)我的發(fā)現(xiàn),indexOf的第二個(gè)參數(shù)傳進(jìn)去有用,lastIndexOf第二個(gè)參數(shù)跟沒傳一樣
15:forEach();
功能:ES5新增的方法,用來遍歷數(shù)組,沒有返回值,
參數(shù):forEach(callback);callback默認(rèn)有三個(gè)參數(shù),分別為value(遍歷到的數(shù)組的數(shù)據(jù)),index(對(duì)應(yīng)的索引),self(數(shù)組自身)。
var arr = ["Tom","Jack","Lucy","Lily","May"]; var a = arr.forEach(function(value,index,self){ console.log(value + "--" + index + "--" + (arr === self)); }) // 打印結(jié)果為: // Tom--0--true // Jack--1--true // Lucy--2--true // Lily--3--true // May--4--true console.log(a); //undefined---forEach沒有返回值 //該方法為遍歷方法,不會(huì)修改原數(shù)組
16:map();
功能:
1.同forEach功能;
2.map的回調(diào)函數(shù)會(huì)將執(zhí)行結(jié)果返回,最后map將所有回調(diào)函數(shù)的返回值組成新數(shù)組返回。
參數(shù):map(callback);callback默認(rèn)有三個(gè)參數(shù),分別為value,index,self。跟上面的forEach()的參數(shù)一樣
//功能1:同forEach var arr = ["Tom","Jack","Lucy","Lily","May"]; var a = arr.map(function(value,index,self){ console.log(value + "--" + index + "--" + (arr === self)) }) // 打印結(jié)果為: // Tom--0--true // Jack--1--true // Lucy--2--true // Lily--3--true // May--4--true //功能2:每次回調(diào)函數(shù)的返回值被map組成新數(shù)組返回 var arr = ["Tom","Jack","Lucy","Lily","May"]; var a = arr.map(function(value,index,self){ return "hi:"+value; }) console.log(a); //["hi:Tom", "hi:Jack", "hi:Lucy", "hi:Lily", "hi:May"] console.log(arr); //["Tom", "Jack", "Lucy", "Lily", "May"]---原數(shù)組未改變
17:filter();
功能:1.同forEach功能;2.filter的回調(diào)函數(shù)需要返回布爾值,當(dāng)為true時(shí),將本次數(shù)組的數(shù)據(jù)返回給filter,最后filter將所有回調(diào)函數(shù)的返回值組成新數(shù)組返回(此功能可理解為“過濾”)。
參數(shù):filter(callback);callback默認(rèn)有三個(gè)參數(shù),分別為value,index,self。
//功能1:同forEachvar arr = ["Tom","Jack","Lucy","Lily","May"];var a = arr.filter(function(value,index,self){ console.log(value + "--" + index + "--" + (arr === self))})// 打印結(jié)果為:// Tom--0--true// Jack--1--true// Lucy--2--true// Lily--3--true// May--4--true//功能2:當(dāng)回調(diào)函數(shù)的返回值為true時(shí),本次的數(shù)組值返回給filter,被filter組成新數(shù)組返回var arr = ["Tom","Jack","Lucy","Lily","May"];var a = arr.filter(function(value,index,self){ return value.length > 3;})console.log(a); //["Jack", "Lucy", "Lily"]console.log(arr); //["Tom", "Jack", "Lucy", "Lily", "May"]---原數(shù)組未改變//功能1:同forEach var arr = ["Tom","Jack","Lucy","Lily","May"]; var a = arr.filter(function(value,index,self){ console.log(value + "--" + index + "--" + (arr === self)) }) // 打印結(jié)果為: // Tom--0--true // Jack--1--true // Lucy--2--true // Lily--3--true // May--4--true //功能2:當(dāng)回調(diào)函數(shù)的返回值為true時(shí),本次的數(shù)組值返回給filter,被filter組成新數(shù)組返回 var arr = ["Tom","Jack","Lucy","Lily","May"]; var a = arr.filter(function(value,index,self){ return value.length > 3; }) console.log(a); //["Jack", "Lucy", "Lily"] console.log(arr); //["Tom", "Jack", "Lucy", "Lily", "May"]---原數(shù)組未改變
18:every();
功能:判斷數(shù)組中每一項(xiàng)是否都滿足條件,只有所有項(xiàng)都滿足條件,才會(huì)返回true。
參數(shù):every()接收一個(gè)回調(diào)函數(shù)作為參數(shù),這個(gè)回調(diào)函數(shù)需要有返回值,every(callback);callback默認(rèn)有三個(gè)參數(shù),分別為value,index,self。
功能1:當(dāng)回調(diào)函數(shù)的返回值為true時(shí),類似于forEach的功能,遍歷所有;如果為false,那么停止執(zhí)行,后面的數(shù)據(jù)不再遍歷,停在第一個(gè)返回false的位置。
//demo1: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.every(function(value,index,self){ console.log(value + "--" + index + "--" + (arr == self)) }) // 打印結(jié)果為: // Tom--0--true //因?yàn)榛卣{(diào)函數(shù)中沒有return true,默認(rèn)返回undefined,等同于返回false //demo2: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.every(function(value,index,self){ console.log(value + "--" + index + "--" + (arr == self)) return value.length < 4; }) // 打印結(jié)果為: // Tom--0--true // abc--1--true // Jack--2--true //因?yàn)楫?dāng)遍歷到Jack時(shí),回調(diào)函數(shù)到return返回false,此時(shí)Jack已經(jīng)遍歷,但是后面數(shù)據(jù)就不再被遍歷了 //demo3: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.every(function(value,index,self){ console.log(value + "--" + index + "--" + (arr == self)) return true; }) // 打印結(jié)果為: // Tom--0--true // abc--1--true // Jack--2--true // Lucy--3--true // Lily--4--true // May--5--true //因?yàn)槊總€(gè)回調(diào)函數(shù)的返回值都是true,那么會(huì)遍歷數(shù)組所有數(shù)據(jù),等同于forEach功能
功能2:當(dāng)每個(gè)回調(diào)函數(shù)的返回值都為true時(shí),every的返回值為true,只要有一個(gè)回調(diào)函數(shù)的返回值為false,every的返回值都為false
//demo1: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.every(function(value,index,self){ return value.length > 3; }) console.log(a); //false //demo2: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.every(function(value,index,self){ return value.length > 2; }) console.log(a); //true
19:some();
功能:判斷數(shù)組中是否存在滿足條件的項(xiàng),只要有一項(xiàng)滿足條件,就會(huì)返回true。
參數(shù):some()接收一個(gè)回調(diào)函數(shù)作為參數(shù),這個(gè)回調(diào)函數(shù)需要有返回值,some(callback);callback默認(rèn)有三個(gè)參數(shù),分別為value,index,self。
功能1:因?yàn)橐袛鄶?shù)組中的每一項(xiàng),只要有一個(gè)回調(diào)函數(shù)返回true,some都會(huì)返回true,所以與every正好相反,當(dāng)遇到一個(gè)回調(diào)函數(shù)的返回值為true時(shí),可以確定結(jié)果,那么停止執(zhí)行,后面都數(shù)據(jù)不再遍歷,停在第一個(gè)返回true的位置;當(dāng)回調(diào)函數(shù)的返回值為false時(shí),需要繼續(xù)向后執(zhí)行,到最后才能確定結(jié)果,所以會(huì)遍歷所有數(shù)據(jù),實(shí)現(xiàn)類似于forEach的功能,遍歷所有。
//demo1: var arr = ["Tom","abc","Jack","Lucy","Lily","May"]; var a = arr.some(function(value,index,self){ console.log(value + "--" + index + "--" + (arr == self)) return value.length > 3; }) // 打印結(jié)果為: // Tom--0--true // abc--1--true // Jack--2--true
20.reduce();
迭代數(shù)組的所有項(xiàng),累加器,數(shù)組中的每個(gè)值(從左到右)合并,最終計(jì)算為一個(gè)值
參數(shù):
callback:
previousValue
必選 --上一次調(diào)用回調(diào)返回的值,或者是提供的初始值(initialValue)
currentValue
必選 --數(shù)組中當(dāng)前被處理的數(shù)組項(xiàng)
index
可選 --當(dāng)前數(shù)組項(xiàng)在數(shù)組中的索引值
array
可選 --原數(shù)組
initialValue
: 可選 --初始值
實(shí)行方法:回調(diào)函數(shù)第一次執(zhí)行時(shí),preValue 和 curValue 可以是一個(gè)值,如果 initialValue 在調(diào)用 reduce() 時(shí)被提供,那么第一個(gè) preValue 等于 initialValue ,并且curValue 等于數(shù)組中的第一個(gè)值;如果initialValue 未被提供,那么preValue 等于數(shù)組中的第一個(gè)值.
let arr = [0,1,2,3,4] let arr1 = arr.reduce((preValue, curValue) => preValue + curValue ) console.log(arr1) // 10 let arr2 = arr.reduce((preValue,curValue)=>preValue + curValue,5) console.log(arr2) // 15
arr.reduce()拓展(高級(jí)用法)
(1)計(jì)算數(shù)組中每個(gè)元素出現(xiàn)的次數(shù)
let arr = [0,1,2,3,4] let arr1 = arr.reduce((preValue, curValue) => preValue + curValue ) console.log(arr1) // 10 let arr2 = arr.reduce((preValue,curValue)=>preValue + curValue,5) console.log(arr2) // 15
(2)數(shù)組去重
let arr = [1,2,3,4,4,1] let newArr = arr.reduce((pre,cur)=>{ if(!pre.includes(cur)){ return pre.concat(cur) }else{ return pre } },[]) console.log(newArr);// [1, 2, 3, 4]
(3)將多維數(shù)組轉(zhuǎn)化為一維
let arr = [[0, 1], [2, 3], [4,[5,6,7]]] const newArr = function(arr){ return arr.reduce((pre,cur)=>pre.concat(Array.isArray(cur)?newArr(cur):cur),[]) } console.log(newArr(arr)); //[0, 1, 2, 3, 4, 5, 6, 7]
21.reduceRight()
功能:(與reduce類似)從數(shù)組的最后一項(xiàng)開始,向前逐個(gè)遍歷到第一位,迭代數(shù)組的所有項(xiàng),然后構(gòu)建一個(gè)最終返回的值。
參數(shù):同reduce。 demo:同reduce
22 Array.from()
將偽數(shù)組變成數(shù)組,就是只要有l(wèi)ength的就可以轉(zhuǎn)成數(shù)組。 —es6
let str = '12345' console.log(Array.from(str)) // ["1", "2", "3", "4", "5"] let obj = {0:'a',1:'b',length:2} console.log(Array.from(obj)) // ["a", "b"] let aa= {0:'a',1:'b'} console.log(Array.from(aa)) // []
原來的不會(huì)發(fā)生改變
23 Array.of()
將一組值轉(zhuǎn)換成數(shù)組,類似于聲明數(shù)組 —es6
let str = '11' console.log(Array.of(str)) // ['11'] // 等價(jià)于 console.log(new Array('11')) // ['11]
ps:但是new Array()有缺點(diǎn),就是參數(shù)問題引起的重載
console.log(new Array(2)) //[empty × 2] 是個(gè)空數(shù)組 console.log(Array.of(2)) // [2]
24 arr.copyWithin()
在當(dāng)前數(shù)組內(nèi)部,將制定位置的數(shù)組復(fù)制到其他位置,會(huì)覆蓋原數(shù)組項(xiàng),返回當(dāng)前數(shù)組
參數(shù):
target
--必選 索引從該位置開始替換數(shù)組項(xiàng)start
--可選 索引從該位置開始讀取數(shù)組項(xiàng),默認(rèn)為0.如果為負(fù)值,則從右往左讀。end
--可選 索引到該位置停止讀取的數(shù)組項(xiàng),默認(rèn)是Array.length,如果是負(fù)值,表示倒數(shù)
let arr = [1,2,3,4,5,6,7]let arr1 = arr.copyWithin(1)console.log(arr1) // [1, 1, 2, 3, 4, 5, 6]let arr2 = arr.copyWithin(1,2)console.log(arr2) // [1, 3, 4, 5, 6, 7, 7]let arr3 = arr.copyWithin(1,2,4)console.log(arr3) // [1, 3, 4, 4, 5, 6, 7]
哪些數(shù)組方法會(huì)改變?cè)瓟?shù)組
- unshift();
- push();
- shift();
- pop();
- sort();
- reverse();
- splice();
- copyWithin()
這八個(gè)數(shù)組方法在上面都有過介紹了,可以看出,再用這些方法的時(shí)候,原數(shù)組是會(huì)被改變的。
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
document.getElementById獲取控件對(duì)象為空的解決方法
今天寫個(gè)網(wǎng)頁,想在頁面加載onLoad時(shí),動(dòng)態(tài)顯示由后臺(tái)其他程序傳來的數(shù)據(jù)時(shí),用document.getElementById獲取控件對(duì)象總是為空。但是檢查了這個(gè)id確實(shí)是存在的??聪挛牡氖纠徒鉀Q方法2013-11-11JavaScript ES6中的簡(jiǎn)寫語法總結(jié)與使用技巧
我們?cè)诳淳帉懙腏S ES6代碼時(shí)經(jīng)常會(huì)看到許多簡(jiǎn)寫的語法,本篇文章就為大家一一介紹JavaScript ES6可以簡(jiǎn)寫的語法2018-12-12JavaScript中的prototype原型學(xué)習(xí)指南
這篇文章主要介紹了JavaScript中的prototype原型學(xué)習(xí)指南,包括原型鏈與原型繼承等重要知識(shí),需要的朋友可以參考下2016-05-05JavaScript 學(xué)習(xí)筆記之操作符(續(xù))
上篇文章我們講解了javascript的操作符中的一元操作符、位操作符、布爾操作符,今天我們繼續(xù)講解剩下的幾個(gè)操作符,包括乘性操作符、加性操作符、相等操作符、條件操作符、賦值操作符、逗號(hào)操作符,小伙伴們仔細(xì)研讀下吧,對(duì)提高自己對(duì)于javascript的理解很有幫助。2015-01-01javascript基礎(chǔ)知識(shí)分享之類與函數(shù)化
在C++中是以class來聲明一個(gè)類的,JavaScript與C++不同,它使用了與函數(shù)一樣的function來聲明,這就讓許多學(xué)Jscript的朋友把類與函數(shù)混在一起了,在Jscript中函數(shù)與類確實(shí)有些混,但使用久了自然會(huì)理解,這篇文章是針對(duì)想進(jìn)攻面向?qū)ο缶幊痰呐笥讯鴮?就不打算討論得太深了2016-02-02javaScript parseInt字符轉(zhuǎn)化為數(shù)字函數(shù)使用小結(jié)
前幾天做網(wǎng)站的時(shí)候需要講數(shù)據(jù)庫(kù)中的時(shí)間讀取到變量中進(jìn)行使用,用到parseInt函數(shù),講字符轉(zhuǎn)化為數(shù)字。2009-11-11javascript深拷貝、淺拷貝和循環(huán)引用深入理解
本文給大家詳細(xì)講述了javascript深拷貝、淺拷貝和循環(huán)引用的相關(guān)知識(shí)點(diǎn),對(duì)此有興趣需求的朋友學(xué)習(xí)下。2018-05-05JavaScript_object基礎(chǔ)入門(必看篇)
下面小編就為大家?guī)硪黄狫avaScript_object基礎(chǔ)入門(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06