본문 바로가기 메뉴 바로가기

대표이미지

[javascript] Array 셔플(랜덤), remove Array

2022. 1. 25.

index.html
0.00MB

//var this_numarry = new Array();
var this_numarry = ['09', '11', '23', '32', '15', '41', '19'];

function removeNumberArray(target_){
    if(this_numarry != undefined && this_numarry.length > 0){
                                    const index = this_numarry.indexOf(target_); 
                                    if (index > -1) { this_numarry.splice(index, 1); }
    }
}

function setShuffleArray(array) { 
    let currentIndex = array.length, randomIndex; // While there remain elements to shuffle... 
    while (currentIndex != 0) { // Pick a remaining element... 
        randomIndex = Math.floor(Math.random() * currentIndex); 
        currentIndex--; // And swap it with the current element.
        [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex]]; 
    } 
	return array; 
}
댓글 갯수
TOP