Task Description: Develop a function named displayOptions that takes an object called "displayDevice" as input and returns an array. The properties of the input object will be various "video output" options, each with either a true or false value. Your task is to extract all the names of the "video output" with true values.
I attempted to solve this problem using the .filter() method, but I would like to explore a solution utilizing a for..in loop. While I managed to iterate through the object, my current implementation includes all keys in the array, not just the ones with a "true" value. Please help me identify where I went off track in my approach.
Here's My Current Code:
function displayOptions(displayDevice) {
for(var key in displayDevice) {
if(displayDevice[key] === true) {
return Object.keys(displayDevice);
}
}
}
var televisionA = {
VGA: false,
HDMI1: true,
HDMI2: true
}
var monitor001 = {
VGA: true,
DVI: false,
HDMI1: true,
HDMI2: true
}
var monitor002 = {
HDMI1: true,
HDMI2: true,
DVI: true
}
displayOptions(televisionA); //["HDMI1", "HDMI2"];
displayOptions(monitor001); //["VGA", "HDMI1", "HDMI2"];