Base on your code, the value you get is a string not an object. so the code : var relateditmid = relateditm[0].ItemId; will return the item ID after converting the string relateditm to Object using eval funtion.
var relateditmObj = eval(relateditm); var relateditmid = relateditmObj[0].ItemId;