In some languages, if a function returns an array, then as opposed to storing the array in a variable then retrieving a single element, like this:
var someValues = getSomeValues();
var firstElement = someValues[0];
You can use the array index notation directly after the function call to retrieve the element of the returned array instead, like this:
var firstElement = getSomeValues()[0];
What is this construct or syntax known as? Does it have a special name at all?
You can use the array index notation directly on the function call to retrieve the element
var firstElement = getSomeValues()[0];
What you are doing is accessing the indexed element of the array/collection returned by the function. You are not directly accessing an index in a function.
I would call this "chaining" an indexer to the return value.
Array dereferencing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With