??javascript??java?е?????
???????????? ???????[ 2015/5/12 13:35:05 ] ????????????????
????javascript?е?????
????????????
????????????? var str = ['java'?? 'js'];
???????new????????? var a = new Array(10); // ???嶠???10?????饗???
????????new?????????var a = new Array(1?? 2?? 3?? 4?? 5); var b = [1?? 2?? 3?? 4?? 5];
??????????饗??????????????var a = new Array([1??2??3]?? [4??5??6]?? [7??8??9]); var b = [[1??2??3]?? [4??5??6]?? [7??8??9]];
???????????????????js?е????鳤??????????“?????”????????????????????
??????????б?
?????????????????????js??????ж???????????????????
???????к?????????о??????????????Щ?ж????
????1 //???????????
????2 console.log(typeof []) //object
????3 // ?????
????4 var arr = [1??2??3];
????5 console.log(arr.constructor === Array)//true
????6 //??????
????7 console.log(arr instanceof Array) //true
????8 //??????
????9 console.log(Object.prototype.toString.call(arr) === '[object Array]')//true
????10 //??????
????11 Array.isArray(arr) //es5 ?·???
???????????÷???
????arr. push();// ???????????????????????β?????????????3???
????arr.unshift();// ??????????????????????????????????3???
????arr.splice(arg1??arg2??arg3); //?????????????????
????arr.pop(); //?????????????????????
????arr.shift(); //?????????????????????????????????????
????arr.slice(start?? [end]); //???????????????????????????????? end ????????
????arrayObj.reverse(); //????????????????????????
????arrayObj.sort(); //???????????????????????
????es5 ?????????鷽????????????????
1 //???????????磬??????????????
2 // ??????????飬?洢???????????????
3 var array = [8?? 2?? 1?? 5]??
4 array2 = [
5 [0?? 1]??
6 [1?? 2]??
7 [2?? 3]
8 ]??
9 value;
10
11 /// Array.prototype.reduce = function(callback??initialValue) {};
12 // ???????飺
13 // ????reduce ????????????????
14 // ??????? ?????lenght - 1?? ???????
15 // ?????? previousValue ? initialValue
16 // ??? reduce?????????? ??? previousValue
17
18 // reduceRight ??????????????????????????
19
20 // ????????????
21 value = array.reduce(function (previousValue?? currentValue?? index?? array) {
22 return previousValue + currentValue;
23 }
24 );
25 console.log(value); // 16
26
27 // ????????
28 value = array2.reduce(function (previousValue?? currentValue?? index?? array) {
29 return previousValue.concat(currentValue);
30 }
31 );
32 console.log(value); // [ 0?? 1?? 1?? 2?? 2?? 3 ]
33
34 /// Array.prototype.indexOf = function(searchElement??fromIndex) {};
35 // ??fromIndex?????? ??????searchElement??? ???????????????????????-1
36 // fromIndex ???? 0
37 console.log(array.indexOf(1)); // 2
38 console.log(array.indexOf(3)); // -1
39
40 /// Array.prototype.lastIndexOf = function(searchElement??fromIndex) {};
41 // ??fromIndex?????? ??????searchElement??? ???????????????????????-1
42 console.log(array.lastIndexOf(1)); // 2
43 console.log(array.lastIndexOf(3)); // -1
44
45 /// Array.prototype.every = function(callback??thisObject) {};
46 // ????????????????????????????????????
47 value = array.every(function (element?? index?? array) {
48 return element > 1;
49 });
50 console.log(value); // false
51
52
53 /// Array.prototype.filter = function(callback??thisObject) {};
54 // ????????
55 // ???????????????? ???(??????????????true???????????????? )???????μ?????
56 value = array.filter(function (element?? index?? array) {
57 return element > 1;
58 });
59 console.log(value);// [ 8?? 2?? 5 ]
60
61
62 /// Array.prototype.forEach = function(callback??thisObject) {};
63 // ????????????????λ????????
64 array.forEach(function (element?? index?? array) {
65 console.log(element);
66 });
67
68
69 /// Array.prototype.map = function(callback??thisObject) {};
70 // ???????
71 // ???????????????е????????????????????????????????????顣
72 value = array.map(function (element?? index?? array) {
73 return element * element;
74 });
75 console.log(value); // [ 64?? 4?? 1?? 25 ]
76
77
78 /// Array.prototype.some = function(callback??thisObject) {};
79 // ?????????е??Щ????????????????????????
80 value = array.some(function (element?? index?? array) {
81 return element > 1;
82 });
83 console.log(value); // true
84
85
86 /// Array.prototype.isArray = function(object) {};
87 // ?ж????????????????
88 console.log(Array.isArray(array)); // true
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11