Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Instructions from your teacher:
- // Write a function called "getNthElementOfProperty".
- // Given an object and a key, "getNthElementOfProperty" returns the nth element of an array located at the given key.
- // Notes:
- // * If the array is empty, it should return undefined.
- // * If n is out of range, it should return undefined.
- // * If the property at the given key is not an array, it should return undefined.
- // * If there is no property at the key, it should return undefined.
- function getNthElementOfProperty(obj, key, n) {
- // your code here
- if(Array.isArray(obj[key])) {
- return obj[key][n]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement