Return the split path if the JSON key/value exists else return blank

Return the split path if the JSON key/value exists else return blank

I need to display the name and split path of the path entered by a user dynamically.
For that, I had split the path entered by the user and grab only certain part of it. For e.g. if the user enters path as:

/content/mypath/myfolder/about/images/abc.jpg
Then I am displaying images/abc.jpg.

However, let's assume that some of the users do not have a picture, at least the name should be applied & displayed in that case. 

Please check the function refreshDisplay() for details.
But it throws an error- Uncaught TypeError: Cannot read property 'match' of undefined