Me again!
This time I’m supposed to create a function that takes 2 parameters (arr, obj ) that when invoked creates an object with only the properties pulled from the original obj that match the value of a given array.
function select(arr, obj) {
newObj = {};
for ( i = 0; i < arr.length; i++){
if( obj.hasOwnProperty(i) ){
newObj[i] = obj[i];
}
}
return newObj;
}
Can anybody tell me what part of my code is wrong? Remember it returns a new object whose properties are those in the given object AND whose keys are present in the given array.
Notes:
- If keys are present in the given array, but are not in the given object, it should ignore them.
- It does not modify the passed in object.
Thanks