I'm currently practicing some basic problem in js and fairly new to any of these languages. I want to retrieve the value and name of the property into an array "temp" from the object "second" if the another obj "third" has the same property value. I can do it, when the property name is already defined, but how can I do the same if I don't know the actual property name. May be using Object.keys()
My code is something like this:
      function where(second, third) {
  var arr = [];
  var temp=[];
  for(var i in second)
    {
      if(third.hasOwnProperty('last')){
        if(second[i].last===third.last){
          arr=second[i];
          temp.push(arr);
        }
      }
      if(third.hasOwnProperty('first')){
        if(second[i].first===third.first){
          arr=second[i];
          temp.push(arr);
        }
      }
    }
  return temp;
}
where([{ first: 'Ram', last: 'Ktm' }, { first: 'Sam', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });
The resulting array is : [{ 'first': 'Tybalt', 'last': 'Capulet' }]
How can I retrieve the same result even if I don't know the actual property name. For instance the name here first and last might be food, and uses which is unknown. I've already gone with the following threads here.
[2]: https://stackoverflow.com/questions/4607991/javascript-transform-object-into-array
[1]: https://stackoverflow.com/questions/4607991/javascript-transform-object-into-array
 
     
     
     
    