Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if array in conditional chaining javascript

const x = thisIsPossiblyAnArray?.[0];
if (x) {
 console.log("the value of index 0 is", x);
} else {
 console.log("x is undefined as thisIsPossiblyAnArray is either not an Array or is an Array with no item at index 0")
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #array #conditional #chaining #javascript
ADD COMMENT
Topic
Name
7+3 =