Can you aid me in achieving the following output by comparing var1 and var2, and obtaining the output based on var2 where the keys are provided in a string array?
var1 = {a:1, b:2, c:3, d:4};
var2 = ['a', 'd'];
The expected output is:
var3 = {a:1, d:4};