arr[arr.length] = 'a';
delete numbers[2];
// ['zero','one',undefined,'go']
numbers.splice(2,1);
// ['zero','one','go']
var is_array = function(value){
return value &&
typeof value === 'object' &&
value.constructor === Array;
};
Array.matrix = function (m,n, initial){
var a, i, j,mat = [];
for (i = 0; i < m; i += 1){
a = [];
for (j = 0; j < n; j += 1){
a[j] = 0;
}
mat[i= a;
}
return mat;
}
// 製作一個 4 * 4 填滿 0 的矩陣
var myMatrix = Array.matrix(4,4,0);
document.writeln(myMatrix[3][3]); // 0
資料來源:《JavaScript 優良部份》 Douglas Crockford 著 歐萊禮
筆記純屬推廣及分享,如有侵權,請告知。
Please advise to remove immediately if any infringement caused.