In general it's sort of a gray area... what do you mean by "has a value"? The values null
and undefined
are legitimate values you can assign to a variable...
The String function split()
always returns an array so use the length
property of the result to figure out which indices are present. Indices out of range will have the value undefined
.
But technically (outside the context of String.split()
) you could do this:
js>z = ['a','b','c',undefined,null,1,2,3]
a,b,c,,,1,2,3
js>typeof z[3]
undefined
js>z[3] === undefined
true
js>z[3] === null
false
js>typeof z[4]
object
js>z[4] === undefined
false
js>z[4] === null
true