How to check if key exists in object with TypeScript

2 Answers

0 votes
const obj = {
  	typescript: true,
  	php: false,
  	cpp: true,
  	python: false
};
 
console.log("typescript" in obj);
 
   
     
     
/*
run:
     
true
     
*/

 



answered Jul 13, 2022 by avibootz
0 votes
const obj = {
  	typescript: true,
  	php: false,
  	cpp: true,
  	python: false
};
 
console.log(obj.go ? "Yes" : "No");
 
   
     
     
/*
run:
     
"No"
     
*/

 



answered Jul 13, 2022 by avibootz

Related questions

1 answer 175 views
2 answers 149 views
2 answers 189 views
1 answer 144 views
1 answer 126 views
...