I am brand new to coding. Im having issues adding input to the end of my array
function my_array_add(arr, value){
arr.push (value);
}
console.log (my_array_add(arr, 9));
I just keep getting undefined. What am I missing/doing wrong?
If you just want to add an input to the end of an array, you can simplify the operation without writing an extra function. .push is the function you need to accomplish the desired outcome.
let arr = []; // first initialize an empty array
arr.push(input_1); // assume input_1 = 1, it can be anything in general
arr.push(input_2); // assume input_2 = 2
console.log(array); // output : [1,2]
arrinside functionreturn arr;. Functions without an explicit return always implicitly returnundefined.