Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // Instructions from your teacher:
  2. // Write a function called "getNthElementOfProperty".
  3.  
  4. // Given an object and a key, "getNthElementOfProperty" returns the nth element of an array located at the given key.
  5.  
  6. // Notes:
  7. // * If the array is empty, it should return undefined.
  8. // * If n is out of range, it should return undefined.
  9. // * If the property at the given key is not an array, it should return undefined.
  10. // * If there is no property at the key, it should return undefined.
  11.  
  12. function getNthElementOfProperty(obj, key, n) {
  13. // your code here
  14. if(Array.isArray(obj[key])) {
  15. return obj[key][n]
  16. }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement