Is there a more concise and elegant way to check if ['pk'] exists in the first item of an array before executing certain tasks? The array may not always have data, leading to bloated code.
I'm looking for a streamlined solution in Javascript that avoids console errors when the array is empty. Any suggestions?
var $selectedItem = $scope.selectedItem[0] || null;
if($selectedItem && $selectedItem['pk']) { ... }