0

I am learning about new keywords and have homework 1. I wrote a code to remove a property from the object using the delete operator. So is there any way I don't use delete operator, I still remove it? And using new keyword?

var student = { 
  name : "David Rayy", 
  sclass : "VI", 
  rollno : 12 
};

function updateObj() {
  var result = delete student.rollno;
  return student;
}

updateObj()

/* expect
    var student = { 
      name : "David Rayy", 
      sclass : "VI", 
    }; 
*/
  1. Write a function to show all info of student. I haven't done it yet
var student = {
  name: 'Herry',
  gender: 'male',
  age: 18
}

function showInfo(obj) {

}

showInfo();
Hoang Dinh
  • 157
  • 1
  • 10
  • Possible duplicate of [How do I remove a property from a JavaScript object?](https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object) – nCoder May 08 '19 at 02:17
  • Yes, but I don't want to remove a property using `delete` operator – Hoang Dinh May 08 '19 at 02:20

1 Answers1

0

This question is a duplicate of "How do I remove a property from a JavaScript object?", because that question does discuss the alternative.

The "alternative", in this case, is student.rollno = undefined.

This method also has the advantage of being 100 times faster than delete.

nCoder
  • 106
  • 9