I'm looking to create a new function with the following requirements:
Function add(arr,...newVal){
}
array = [1,2,3];
add(array,0)
console.log(array); //I want this to output [0,1,2,3]
I tried creating the function similar to push like this:
Function add(arr,...newVal){
for(var i=0; i<arr.length; i++){
arr[arr.length]=newVal[i];
}return arr.length;
}
array = [1,2,3];
add(array,4)
console.log(array); // Expected output is [1,2,3,4]