Advertisement
makispaiktis

Object/Directory Methods

Oct 21st, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const robot = {
  2.     model: 'SAL-1000',
  3.   mobile: true,
  4.   sentient: false,
  5.   armor: 'Steel-plated',
  6.   energyLevel: 75
  7. };
  8.  
  9. // Keys, values, entries (items)
  10. const robotKeys = Object.keys(robot);
  11. console.log(robotKeys);
  12. const robotValues = Object.values(robot);
  13. console.log(robotValues);
  14. const robotEntries = Object.entries(robot);
  15. console.log(robotEntries);
  16. console.log('\n');
  17.  
  18. // Assign (1st argument CHANGES, while the 2nd one does NOT change)
  19. let tempRobot = {laserBlaster : true, voiceRecognition: true};
  20. const newRobot = Object.assign(tempRobot, robot);
  21. console.log(newRobot);
  22. console.log('\n----> robot remains unchanged (it is the 2nd argument of assign) <----\n');
  23. console.log(robot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement