The problem is not with what filter()
returns, instead it is with what push()
returns.
push()
returns the new length of the array, and not the array itself.
So when you do:
var arr2 = arr.filter(function(elmnt) { return elmnt.indexOf("a") > -1; }).push("aaa");
arr2
will be assigned the new length of the array (which happens to be 4 in your case), and not the new array as such.
A modified version that'll do what you want would be:
var arr = ["a", "ab", "c", "ad"], arr2;
(arr2 = arr.filter(function(elmnt) { return elmnt.indexOf("a") > -1; })).push("aaa");
// now arr2 is ["a", "ab", "ad", "aaa"]