In short, it is safe. XSS may require escaping from a javascript ( ") or script ( </script>) string . Both lines are correctly escaped:
" becomes \"
</script> becomes <\/script>
This is part of direct injection. Your application should consider that some elements of the array may be missing. Another possibility is that the element of the array is not the type you expect (for example, an array instead of a string).