# 练习join（连接两个数组），随机数组的练习

<script>
function join(arr1,arr2) {
//将arr2的内容push到arr1中。然后再join
for (let i = 0; i < arr2.length; i++) {
arr1.push(arr2[i]);
}
return arr1.join("");
}
var arr1 = [1,2,3];
var arr2 = [4,5,6];
console.log (join(arr1,arr2));
</script>


1：得到一个随机数组，20个元素，元素取值范围[1-20]，利用之前得到随机数组的方法。

<script>
function random(min, max) {
return ~~(Math.random () * (max - min) + min);
}

function randomArray(len, min, max) {
var arr = [];
for (let i = 0; i < len; i++) {
arr.push(random(min,max));
}
return arr;
}

function modifyArray(array,delValue,modValue,newValue) {
for (let i = 0; i < array.length; i++) {
if(array[i] === delValue){
array.splice(i,1);
continue;
}
if(array[i] === modValue){
array.splice(i,1,newValue);
continue;
}
}
}

var array = randomArray(20,1,20);
console.log (array);
var delValue = 4;
var modValue = 14;
var newValue = 17;
modifyArray(array,delValue,modValue,newValue);
console.log (array);

</script>

04-08 115万+
07-21 2688

04-03 21
06-26 186
05-06 162
10-12 9024
06-03 32
06-12 35
12-16 248