As you can see I am printing object property values but I can’t print double underscore instead of ‘__’ missing property value.
function findAddress(obj){
let object = Object.values(obj);
for(let i = 0; i < obj.length; i++){
const objects = obj[i];
if(objects[values] === object[values] == ''){
return objects.obj[values] = '__' ;
}
else if(objects === object){
object = objects;
}
}
return object;
}
const output = {street : 10, house : '', society : 'Earth Perfect'};
const res = findAddress(output);
console.log(res);
I am trying to print object property values but, if any property value is missing I want to print double underscore ‘__’ instead of missing value. This program is printing object property value but it didn’t printing missing property value.
2
Answers
You can simply achieve this:
You cannot iterate an object (it doesn’t have
length
property by default and number keys). But you can get an array of an object’s keys and reduce them to a new object with needed transformations: