But if the index is undefined, like if you’re at the start or the end of the object I want a way to return nothing, so I’ve tried the ternary like detailed and also the || assignment, but I’m not assigning anything so I’m not sure where to go with this now.
Please correct me if I did not understand you correctly, but from your description, I understand you want to check IF allPosts[index - 1].slug is undefined, use a forward dash?
It wasn’t phrased the best so apologies, your answer is sort of what I want, the thing is, that I need to define only slug I think as I’m getting a type error on that:
Error: TypeError: Cannot read property 'slug' of undefined
No, because if you try to get an out-of-bounds element: that element is undefined, so if you try to access properties on it, eg undefined.slug, that’s a type error.