javascript - Check which variable is undefined in a JS Array -
I am trying to check how the variables (s) are not defined in a variable and their How to do something with
Alex << p>
(window ['user' + i] == undefined) {window ['user' + i] = >
/ var />
There is nothing with two types of undefined properties : those which are not defined, and which are set to undefined
.
If you object properties have not been defined (or array), then Object.prototype.hasOwnProperty ()
use, such as:
for (var i = 0; i & lt; result.length; i ++) {if.! (Object. Prototippi. HasOwnPropertykcall (window, 'user' + i)) {window [ 'user' + i] = // nothing to do with the different determine}}
Since window
is an object, so you can directly call the hasOwnProperty
, if you trust that it ( or Object.prototype.hasOwnProperty
, which window
is inherited) have a set code for this looks like this:
(Var i = 0; i & lt; result.length; i ++) {if (! Window.hasO WnProperty ('user' + i)) {window ['user' + i] = // do something with a variable that is not defined}}
If you specifically recognize the properties set on , then start with the previous check and if true, check the value assuming that any
window HasOwnProperty
, it will look like this:
for (var i = 0; i & lt; result.length; i ++) {if (window.hasOwnProperty ( 'user' + i) & amp; window [ 'user' + i] === undefined) {window [ 'user' + i] = / define something in any way Have not been done}}
You may also have to check for those properties which are undefined, or undefined
or null
. Again assuming that no one can change window.hasOwnProperty
, it may look like:
for (var i = 0; i & Lt; result.length; i ++) (if !! window ['user' + i) || Window ['user' + i] === undefined || Window ['user' + i] === faucet) {window ['user' + I] = // with something different that is not set}}
Comments
Post a Comment