I have simple array look like this
[{"id":"1"},{"id":"2"},{"id":"3"}]
Also attach my array structure in image
I need to shuffle this mean i want some time second array come one first. etc
Something like this [{"id":"2"},{"id":"1"},{"id":"3"}]
or on every shuffle different result come
Any one can tell how is it possible ?
I have try this but dont know how to console the new shuffled array ?
start(CategoryID){
console.log(CategoryID);
this.api.getQuestions(CategoryID).subscribe((data: any)=>{
console.log(data);
data = this.shuffle(data);
});
}
shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}