Function: get()
get<
Value
>(iterable
):Value
Returns the only value in iterable
if it contains exactly one value.
Otherwise, throws an error.
Type Parameters
• Value
Parameters
• iterable: Iterable
<Value
, any
, any
>
Returns
Value
Example
console.log(get([`sloth`]))
//=> sloth
try {
console.log(get([]))
} catch {
console.log(`Oh no! It was empty...`)
}
//=> Oh no! It was empty...
try {
console.log(get([1, `sloth`, 3]))
} catch {
console.log(`Oh no! It had more than one value...`)
}
//=> Oh no! It had more than one value...