There is a syntax error in your code.
return input2.indexOf(n) == -1
}): // <-- should be a semicolon
Your code looks mostly fine. The output is actually [[4, 5]] since you call arrayVal.push(res);. That line is pushing an array into another array, resulting in a nested array. You can use the spread syntax and avoid the nesting: arrayVal.push(...res);. After that, the output is [4, 5].
Full code would be:
function()
{
var input1 = [2,3,4,5];
var input2 = [2,3];
var arrayVal = [];
var res = input1.filter(function (n)
{
return input2.indexOf(n) == -1
});
arrayVal.push(...res);
console.log(arrayVal); // [4, 5]
}
And I'm sure your code is modified for the question, but there's no point in having both res and arrayVal here. You could refactor the code like so:
function() {
var input1 = [2,3,4,5],
input2 = [2,3];
var input1SubtractInput2 = input1.filter(function(n) {
return input2.indexOf(n) === -1
});
console.log(input1SubtractInput2); // [4, 5]
}