Compare the value of two arrays and return the value if they are same and return 0 if values are. Different

My problem statment is i have two arrays having different length in javascript like,

a = [ 1,2,3,4];
b = [ 2,4];

The result i need is

res = [0,2,0,4];

Can anyone please help me out with this.

Thank you,