Hi guys suppose I have following two objects
var obj1 = {one:232,two:3123,three:3232}
var obj2 = {one:323,three:3444,seven:32}
I am trying write a function that will return the properties that are in both objects, assuming that I will always have two objects as arguments. So for my output it'd be awesome to see ["one","three"]
.
Here's what I have written
var extend = function(obj){
var x = Object.keys(arguments[0]);
var y = Object.keys(arguments[1]);
var inter =[];
for(var i = 0; i < x.length; i++){
for(var k = 0; k < y.length;i++){
if(x[i] === y[k]) {
inter.push(y[k]);
}
}
}
return inter;
}
What I expected this to do was to create an array of the properties of both of the objects and check each pair to see if they are equal. If they are I wanted it to push the common items into a new array. For some reason, this doesn't run because it seems to be running indefinitely.
Can anyone help?