0

function cloneArray(array) {
  var l = array.length;
  var copy = new Array();
  var i;
  for (i = 0; i < l; i++) {
    copy[i] = array[i];
  }
  console.log(copy);
}
return;

cloneArray([2, 3, 5]);

Thank you for your help, It doesn't give me an error, but it won't log anything on the console...

3
  • 2
    Why do you have a return statement outside your function? Commented Dec 29, 2015 at 19:13
  • Thank you! That was it, can't make an error with these programming languages lol Commented Dec 29, 2015 at 19:15
  • horrible syntax produce inattentiveness error Commented Dec 29, 2015 at 19:16

1 Answer 1

1

Cloning an array is as easy as .slice(0).

function cloneArray(arr){
  return arr.slice(0);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I'm gonna check that method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.