I have a currently selected layer:
var layer = sketch.getSelectedDocument().selectedLayers.layers;
How to get its parent element?
In different posts I see mentions of parentGroup() function, but there is no such function on "layer" variable in my code.
In 53 you can use
var sketch = require('sketch')
var document = sketch.getSelectedDocument()
var layer = document.selectedLayers.layers
layer.getParentPage() // gets the page
layer.getParentArtboard() // gets the containing artboard
layer.getParentSymbolMaster() // you get the idea now…
You can also use
layer.parent // goes up one level
layer.parent.parent // you can continue to chain all the way up
document.parent // will be undefined
Note: layer.getParentSymbolMaster() will throw exception if the layer itself is a symbolmaster. It would have to better if it could have returned itself and so the user does not have to check the type.