This is code to only output the specified columns of the object. However, I am getting the output 4 times undefined.
const array1 = [{
name: 'k',
age: 5,
sex: 'f'
}, {
name: 'a',
age: 2,
sex: 'm'
}];
const result = function(col, arr) {
for (let obj of col.values()) {
for (let i = 0; i < arr.length; i++) {
console.log(arr[i].obj);
}
}
}
result(['name', 'age'], array1);
arr[i]. These objects have no property namedobj. They havename,age, andsex..objis not a property on the array item?objproperty