uncaught typeerror cannot read property code example
Example 1: cannot read property
Syntax -> ?.
Usage ->
let obj;
console.log(obj.a)
console.log(obj?.a)
Example 2: cannot read property
Seems like one of your values, with a property key of 'value' is undefined. Test that i1, i2and __i are defined before executing the if statements:
var i1 = document.getElementById('i1');
var i2 = document.getElementById('i2');
var __i = {'user' : document.getElementsByName("username")[0], 'pass' : document.getElementsByName("password")[0] };
if(i1 && i2 && __i.user && __i.pass)
{
if( __i.user.value.length >= 1 ) { i1.value = ''; } else { i1.value = 'Acc'; }
if( __i.pass.value.length >= 1 ) { i2.value = ''; } else { i2.value = 'Pwd'; }
}
Example 3: cannot read property
console.log(object.list.map(el => el.name))
const object = {
list: [
{name: 'test'},
{name: 'second'}
]
}
console.log(object.default.size)
console.log(object.list[1]?.age)
console.log(object.default?.color)