Slice and Splice outputs object instead of array

My algorithm for Slice and Splice keeps outputting an object instead of an array and I don’t know why.
Here it is.


function frankenSplice(arr1, arr2, n) {
  var copy2=arr2.slice(0);
  copy2.splice(n,0,arr1.slice(0));
  console.log(typeof copy2);
  return copy2;
}

would someone mind explaining to me why this is making copy2 an array?

Actually. I just realized that all arrays are objects :expressionless:
Can someone tell me why the exercise keeps saying that it wrong? console.log shows the output that the it says it wants, but I am not getting any of the check marks.

Ok. Sorry I keep answering my own questions, but I’m learning a lot and I hope this thread is helpful to someone else.

arr.slice(0) will return an exact replica of arr. so then when used with copy2.splice it was copying an entire array at the n position instead of just the value inside the array. I fixed this by using a spread operator …arr1.slice(0). It looks like this.


function frankenSplice(arr1, arr2, n) {
var copy2=arr2.slice(0);
copy2.splice(n,0,...arr1.slice(0));
console.log(typeof copy2);
return copy2;
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums