reactjs - array value is undefined … how do I test for that -
javascript array value undefined ... how test that
and
how check not-defined variable in javascript
these wrong far i'm concerned :
when trying :
console.log(!fromtoparameters[7].value.firstinput); console.log(!!fromtoparameters[7].value.firstinput); console.log(fromtoparameters[7].value.firstinput === undefined); console.log(typeof fromtoparameters[7].value.firstinput == 'undefined'); console.log(fromtoparameters[7].value.firstinput !== undefined); console.log(typeof fromtoparameters[7].value.firstinput != 'undefined'); but (the entry exists) works fine :
console.log(!fromtoparameters[0].value.firstinput); console.log(!!fromtoparameters[0].value.firstinput); console.log(fromtoparameters[0].value.firstinput === undefined); console.log(typeof fromtoparameters[0].value.firstinput == 'undefined'); console.log(fromtoparameters[0].value.firstinput !== undefined); console.log(typeof fromtoparameters[0].value.firstinput != 'undefined'); false true false true false true
is question of react being different js? why can't same in these stackoverflow threads?
update :
so cannot point missing array element @ all.
check answers below.
i think i'll using array.lenght stored in const check increment against within "for" loop allow or disallow modifying array entries on case-by-case basis.
it's annoying can't ask js if damn var of unexisting array index exists or not.
it seems straightforward stuff : can't point index? no. no not variable nor other variable exists @ index. end of.
the guys @ js should put in note adding simple this.
i'm tempted post code have allows me want (calling index lots of undefineds , getting object ""s instead) it's bit monstrous.
you should this:
console.log(fromtoparameters[7] && fromtoparameters[7].value.firstinput); console.log(!!fromtoparameters[7] && fromtoparameters[7].value.firstinput); console.log( fromtoparameters[7]&& typeof fromtoparameters[7].value.firstinput == 'undefined'); i have added check. if fromtoparameters[7] undefined or null, code not break.

Comments
Post a Comment