0

What if I want to access all the properties of an object , how do I do that?

14th Mar 2019, 1:49 AM
knitish shrestha
knitish shrestha - avatar
3 Answers
+ 8
class Test{ constructor(){ this.s1 = "Raj"; this.s2 = "hi"; this.s3 = "okay"; } } var t1 = new Test(); console.log(t1.s1); console.log(t1.s2); console.log(t1.s3);
14th Mar 2019, 2:37 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 7
You can access only public properties by class' object. If you want to access all properties, then make all of them public. for example #include <iostream> using namespace std; class Test{ public: string a; Test(){ a = "Raj"; } }; int main() { Test t1; cout << t1.a; return 0; }
14th Mar 2019, 1:57 AM
Raj Chhatrala
Raj Chhatrala - avatar
0
Could you please show me the Js way to do it, with couple more properties
14th Mar 2019, 2:05 AM
knitish shrestha
knitish shrestha - avatar