Little weird behaviour in my javascript. I want to make a document.ready cleaner by using functions that return manipulated arrays. 
function manipulateArray(arrayToBeManipulated){
  var result=new Array();
  //...push something in result....
  result.push(arrayToBeManipulated[0]);
  console.log(result);
  return result;
}
The console.log always shows me the correct result. But when I invoke the method
//...code...//
var x=new Array();
//push something into x
var result=manipulateArray(x);
console.log(result);
It always shows me undefined. Is there a reason for this?
EDIT maybe I forgot to tell that the function is called inside a $.ajax request. Could this be the problem?
 
     
    