Is there something like a Safe Navigation Operator that can be used on Arrays?

Yes, what you are looking for is known as the Optional Chaining operator (JavaScript / TypeScript).

The syntax shown in the MDN JavaScript documentation is:

obj.val?.prop
obj.val?.[expr]
obj.arr?.[index]
obj.func?.(args)

So, to achieve what you want, you need to change your example from:

<h6>{{simpleData?[0]}}</h6>

To:

<h6>{{simpleData?.[0]}}</h6>
                 ^

Also see How to use optional chaining with array in Typescript?.

Answer from DavidRR on Stack Overflow

Is there something like a Safe Navigation Operator that can be used on Arrays?

Yes, what you are looking for is known as the Optional Chaining operator (JavaScript / TypeScript).

The syntax shown in the MDN JavaScript documentation is:

obj.val?.prop
obj.val?.[expr]
obj.arr?.[index]
obj.func?.(args)

So, to achieve what you want, you need to change your example from:

<h6>{{simpleData?[0]}}</h6>

To:

<h6>{{simpleData?.[0]}}</h6>
                 ^

Also see How to use optional chaining with array in Typescript?.

Answer from DavidRR on Stack Overflow
🌐
Wikipedia
en.wikipedia.org › wiki › Safe_navigation_operator
Safe navigation operator - Wikipedia
February 2, 2026 - In object-oriented programming, ... operator, null-propagation operator) is a binary operator that returns null if its first argument is null; otherwise it performs a dereferencing operation as specified by the second argument (typically an object member access, array ...
🌐
DEV Community
dev.to › pssingh21 › safe-navigation-operator-bang-bang-bang-192j
Safe Navigation Operator? Bang! Bang Bang!! - DEV Community
March 12, 2021 - In this case, the compiler does ... a safe value. This can also be used in terms of calling a possibly undefined function and array indexes. ... For example it could be used when using React refs. When using refs, the current value may be null if the element is unmounted. In JavaScript every value is assocaiated as either a truthy value or a falsy value. So, a bang(!) as a prefix on a value acts as a logical "not" operator on that ...
Top answer
1 of 16
176

You can use the logical 'OR' operator in place of the Elvis operator:

For example displayname = user.name || "Anonymous" .

But Javascript currently doesn't have the other functionality. I'd recommend looking at CoffeeScript if you want an alternative syntax. It has some shorthand that is similar to what you are looking for.

For example The Existential Operator

zip = lottery.drawWinner?().address?.zipcode

Function shortcuts

()->  // equivalent to function(){}

Sexy function calling

func 'arg1','arg2' // equivalent to func('arg1','arg2')

There is also multiline comments and classes. Obviously you have to compile this to javascript or insert into the page as <script type='text/coffeescript>' but it adds a lot of functionality :) . Using <script type='text/coffeescript'> is really only intended for development and not production.

2 of 16
155

2020 Update

JavaScript now has equivalents for both the Elvis Operator and the Safe Navigation Operator.


Safe Property Access

The optional chaining operator (?.) is currently a stage 4 ECMAScript proposal. You can use it today with Babel.

// `undefined` if either `a` or `b` are `null`/`undefined`. `a.b.c` otherwise.
const myVariable = a?.b?.c;

The logical AND operator (&&) is the "old", more-verbose way to handle this scenario.

const myVariable = a && a.b && a.b.c;

Providing a Default

The nullish coalescing operator (??) is currently a stage 4 ECMAScript proposal. You can use it today with Babel. It allows you to set a default value if the left-hand side of the operator is a nullary value (null/undefined).

const myVariable = a?.b?.c ?? 'Some other value';

// Evaluates to 'Some other value'
const myVariable2 = null ?? 'Some other value';

// Evaluates to ''
const myVariable3 = '' ?? 'Some other value';

The logical OR operator (||) is an alternative solution with slightly different behavior. It allows you to set a default value if the left-hand side of the operator is falsy. Note that the result of myVariable3 below differs from myVariable3 above.

const myVariable = a?.b?.c || 'Some other value';

// Evaluates to 'Some other value'
const myVariable2 = null || 'Some other value';

// Evaluates to 'Some other value'
const myVariable3 = '' || 'Some other value';
🌐
Peeyush Singh's Blog
peeyushmansingh.com › safe-navigation-operator-bang-bang-bang
Safe Navigation Operator? Bang! Bang Bang!!
May 25, 2023 - Safe Navigation Operator Safe navigation operator or optional chaining is now available in JavaScript and TypeScript >= v3.7🎉. It provides easy access to deeply nested values, so checking for nullish (undefined or null) values is simplified.
🌐
Designcise
designcise.com › web › tutorial › does-javascript-have-safe-navigation-operator
Does JavaScript Have Safe Navigation Operator? - Designcise
August 22, 2021 - It evaluates an expression from left-to-right; when/if the left operand evaluates to a nullish value, it stops the execution of the entire chain and short-circuit evaluates the expression to undefined.
🌐
Beyondjava
beyondjava.net › elvis-operator-aka-safe-navigation-javascript-typescript
Elvis Operator (aka Safe Navigation) in JavaScript and TypeScript
In most languages implementing the Elvis operator, the expression null?.firstName simply returns null, relieving the developers of guarding the attribute accesses with countless if statements. Languages like JavaScript are even worse than the average programming languages.
Find elsewhere
🌐
GitHub
github.com › microsoft › TypeScript › issues › 16
Suggestion: "safe navigation operator", i.e. x?.y · Issue #16 · microsoft/TypeScript
July 15, 2014 - Current Status The TC39 proposal is now at stage 3 (🎉🎉🎉🎉🎉) Implementation is in progress You can expect this feature in TypeScript 3.7 We'll update here when it's available in a nightly bui...
Published   Jul 15, 2014
🌐
GitHub
github.com › anand-jain-official › safe-navigator
GitHub - anand-jain-official/safe-navigator: A safe navigation operator for javascript that allows you to access nested objects without throwing an error if you try to access the key of an undefined value.
Update v1.1.0: Arrays inside nested Objects const farm = { farmer: { name: 'Steve', farmAnimals: ['Horse', 'Cow'], animalDetails: [ {horse: { name: 'john'} }, { cow: { name: 'sam' } }], pairs: [['john','michelle'], ['sam','edna']] } }; console.log(safe(farm, 'farmer.farmAnimals[0]')); // will return 'Horse' console.log(safe(farm, 'farmer.animalDetails[0].horse.name')); // will return 'john'; Note: 2D or multi-dmensional arrays are not natively supported in the string passed to safe.
Author   anand-jain-official
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Optional_chaining
Optional chaining (?.) - JavaScript | MDN
You can also use the optional chaining operator with bracket notation, which allows passing an expression as the property name: ... This is particularly useful for arrays, since array indices must be accessed with square brackets.
🌐
Reddit
reddit.com › r/typescript › is there a safe navigation operator for string indexes?
r/typescript on Reddit: Is there a safe navigation operator for string indexes?
November 2, 2022 -

If I try to look up a string index on a nullable object like obj['index'] I get an Object is possibly 'null' error. I know I can do obj && obj['index'] but this gets tiresome especially if you are following multiple levels deep.

obj?['index'] thinks I am trying to do a ternary operator. Is there some sort of way to sugar syntax this?

🌐
Medium
medium.com › @zayani.zied › safe-navigation-operator-optional-chaining-js-and-angular-d253431a2625
Safe Navigation Operator-Optional Chaining (JS and Angular) | by Zied ZAYANI | Medium
February 20, 2023 - The safe navigation operator is implemented in the Angular compiler, in our example the Angular compiler will translate the expression into an equivalent JavaScript expression using the ternary operator to check for null or undefined values.
🌐
Howjavascriptworks
howjavascriptworks.com › home › demystifying the safe navigation operator in angular
Safe Navigation Operator Angular: Learn More
November 2, 2023 - Angular didn’t stop at objects. The Safe Navigation Operator is equally efficient with arrays.
🌐
NGCC in Angular Ivy
iq.js.org › questions › angular › what-is-safe-navigation-operator
What is safe navigation operator?
November 11, 2025 - The safe navigation operator(?)(or known as Elvis Operator) is used to guard against null and undefined values in property paths when you are not aware whether a path exists or not.
🌐
Amitthakkar
amitthakkar.github.io › Safe-Navigation-Operator
Safe Navigation Operator by AmitThakkar
Safe Navigation Operator(?.) is used to avoid error Cannot read property 'propertyName' of undefined.
🌐
YouTube
youtube.com › watch
Using Safe Navigation Operator with Arrays: Tips and Solutions Explained - YouTube
In this video, we dive into the Safe Navigation Operator and its powerful application with arrays in programming. Whether you're dealing with potential null ...
Published   May 3, 2025
🌐
Code Highlights
code-hl.com › home › javascript › tutorials
How to Use Safe Navigation Operator JavaScript for Cleaner Code | Code Highlights
October 2, 2024 - The safe navigation operator is a handy feature in JavaScript that helps you avoid errors when accessing properties of objects. It allows you to safely access deeply nested properties without worrying about whether each level exists.