/* array */ var empty = []; var primes = [2,3,5]; var misc = [1.1, true, "a"]; // var a = new Array(10); // a = [1,2,3]; Object.defineProperty(a, "length", {writable: false}); a.length = 0; //a will not change var keys = Object.keys(o); //获得o对象属性名组成的数组 var values = []; for(var i = 0; i<keys.length; i++) { var key = keys[i]; values[i] = o[key]; } // var a = [1,2,3]; a.join(); //"1,2,3" a.join(" "); //"1 2 3" a.join(""); //"123" /* foreach */ var data = [1,2,3,4,5]; var sum = 0; data.forEach(function(value) { sum += value; }); //element, index, array data.forEach(function(v,i,a) { a[i] = v + 1; });