Perform Different operation in objects

Perform Different operation in objects

<script>

            let demo={

              name:”shairy”,

              age:30,

              “last name”:”kalra”

          }

          alert(demo.name);

          demo.result=”pass”;

          alert(demo.result);

          delete demo.age;

          alert(demo.age);

          demo.name=”abhi”;

          alert(demo.name);

          alert(demo[“last name”]);

          delete demo[“last name”];

          alert(demo[“last name”]);

          let abc = prompt(“What do you want to know about the user?”, “last name”);

          alert( demo[abc] );

          for (let key in demo) {

              alert( key );  //keys

              alert( demo[key] ); //values

          }

</script>

Insert Value in blank object

<script>

            let user={};

            alert(user)

       user.name=”shairy”;

       user.lastName=”kalra”;

      alert(user.name);

       alert(user.lastName);

       user.name=”abhi”;

       alert(user.name);

      delete user.lastName;

       alert(user.lastName);

</script>

Post Your Comments & Reviews

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

*

*