1. 程式人生 > >數組亂序與數組拆解

數組亂序與數組拆解

UNC func fun cti split urn mat ray pro

數組亂序:

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
arr.sort(function () {
return Math.random() - 0.5;
});

數組拆解: flat: [1,[2,3]] --> [1, 2, 3]
Array.prototype.flat = function() {
return this.toString().split(‘,‘).map(item => +item )
}

數組亂序與數組拆解