Given an object and a key, I am creating a function that returns an array containing all the elements of the array located at the given key that are less than 100. Basically, If the array is empty, it should return an empty array. If the array contains no elements less than 100, it should return an empty array. If the property at the given key is not an array, it should return an empty array. If there is no property at the key, it should return an empty array.
Here are my codes so far:
function getElementsLessThan100AtProperty(obj, key) {
if (obj.key < 100) {
return obj.key;
}
}
var obj = {
key: [1000, 20, 50, 500]
};
var output = getElementsLessThan100AtProperty(obj, 'key');
console.log(output); // --> MUST RETURN [20, 50]
Any idea what am I missing?