配列の脱重(オリジナルの書き方+s 6の書き方)

3275 ワード

最初の原生jsの書き方:
	 let arr1 = [];
     let arr2 = [1,22,1,33,33,22,44];
     arr2.forEach(r=>{
     
       if(!arr1.includes(r)) arr1.push(r)
     })
     console.log(arr1); //[1,22,33,44]
es 6の書き方:
	let arr = [...new Set([1,22,1,33,33,22,44])];
	console.log(arr); //[1,22,33,44]