Array length: Difference between revisions
Content added Content deleted
Line 305: | Line 305: | ||
return x; |
return x; |
||
}, null); |
}, null); |
||
}</lang> |
|||
Alternatively, rather than scanning the entire list to simply get the final value, it might sometimes be better to test the length: |
|||
<lang JavaScript>function last(list, defaultValue) { |
|||
return list.length ?list[list.length-1] :defaultValue; |
|||
}</lang> |
}</lang> |
||