How to check array value into Object in Javascript

–JS

var myObj = {
	name: 'Pradeep',
	age: 28,
	state: 'delhi',
	address: [{room:'1bhk', type:'semi'}],
	address2: [{room:'2bhk', type:'none'}],
	address3: [{room:'3bhk', type:'full'}],
}
for(var i=0; i<Object.keys(myObj).length; i++){
	for(var x=0; x<myObj[Object.keys(myObj)[i]].length; x++){
		if(myObj[Object.keys(myObj)[i]][x].room == '1bhk'){
            console.log(myObj[Object.keys(myObj)[i]][x])
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *