Checking Properties
We have the following code...
var key,
obj = {
name: 'john',
surname: 'doe'
};
for ( key in obj ) {
if ( obj.hasOwnProperty( key ) ) {
console.log( key + ' exists in obj' );
console.log( key + ': ' + obj[key] );
continue;
}
console.log( key + " doesn't exist in obj" );
}... and the result of executing it is...
name exists in obj
name: john
surname exists in obj
surname: doe... but we want to get the following result, can you help us?
Write the code to get the expected result.
Last updated
Was this helpful?