admin管理员组文章数量:1402407
let email =Symbol();
let Employee = {
name : "rajesh",
phone :9800000000,
[email] : "[email protected]"
};
let allKeys = {
keyss : Reflect.ownKeys(Employee)
};
console.log(allKeys.keyss);
let privateKeys = {
p : Object.getOwnPropertySymbols(Employee)
};
console.log(privateKeys.p);
let publicKeys = {
pu : Object.getOwnPropertyNames(Employee)
};
console.log(publicKeys.pu)
module.exports = {Employee, allKeys, privateKeys, publicKeys}
let email =Symbol();
let Employee = {
name : "rajesh",
phone :9800000000,
[email] : "[email protected]"
};
let allKeys = {
keyss : Reflect.ownKeys(Employee)
};
console.log(allKeys.keyss);
let privateKeys = {
p : Object.getOwnPropertySymbols(Employee)
};
console.log(privateKeys.p);
let publicKeys = {
pu : Object.getOwnPropertyNames(Employee)
};
console.log(publicKeys.pu)
module.exports = {Employee, allKeys, privateKeys, publicKeys}
**I tried this code in hacker rank for past few days but not passing, I cannot resolve it by my own can any one help me.. The question is:
Create an object Employee with properties:
name as "rajesh" phone as 9800000000, symbol "email" as "[email protected]".
After creating the object, display:
All the keys of object "employee"
Only private keys (symbols)
Only public keys (non symbols)**
Share Improve this question asked May 13, 2020 at 17:12 HarshiniHarshini 211 silver badge3 bronze badges 4- 1 everything looks fine? runs basically as you would expect? Symbol('email') maybe? – user120242 Commented May 13, 2020 at 17:16
- 1 What's the test case that is is failing? – Bergi Commented May 13, 2020 at 17:33
- 1 Your export is a bit weird. Why are you storing the key arrays in single-property objects? – Bergi Commented May 13, 2020 at 17:34
- The exports are auto generated in hackerrank – Harshini Commented May 14, 2020 at 9:52
2 Answers
Reset to default 5let email = Symbol();
let Employee = {
name : "rajesh",
phone :9800000000,
[email] : "[email protected]"
};
let allKeys = Reflect.ownKeys(Employee);
let privateKeys = Object.getOwnPropertySymbols(Employee);
let publicKeys = Object.getOwnPropertyNames(Employee);
module.exports = {Employee, allKeys, privateKeys, publicKeys}
let Employee = {
name : "rajesh",
phone :9800000000,
[Symbol.for('email')] : "[email protected]"
};
let allKeys = Reflect.ownKeys(Employee);
let privateKeys = Object.getOwnPropertySymbols(Employee);
let publicKeys = Object.getOwnPropertyNames(Employee);
module.exports = {Employee, allKeys, privateKeys, publicKeys}
本文标签: javascriptES6 symbols with objects Employee with following conditionsStack Overflow
版权声明:本文标题:javascript - ES6 symbols with objects Employee with following conditions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744324713a2600667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论