Javascript array value is undefined ... how do I test for that
and
How to check a not-defined variable in JavaScript
these are wrong as far as I'm concerned :
when trying to :
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 this (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 it a question of react being different from js? why can't I do the same as in these stackoverflow threads?
UPDATE :
so you cannot point to a missing array element at all.
Check answers below.
I think I'll be using an array.lenght stored in a const that I then check my increment against it within my "for" loop to allow or disallow modifying my array entries on a case-by-case basis.
it's really annoying that you can't just ask js if a damn var of an unexisting array index exists or not.
it seems like this would be straightforward stuff : can't point to the index? then NO. no not this variable nor any other variable exists at this index. end of.
the guys at js definitely should put in a note for adding something as simple as this.
I'm tempted to post my code as I have something that allows for me to do what I want (calling a index with lots of undefineds and getting a object with ""s instead) but it's a bit monstrous.