Categories
JavaScript Answers

How to change property name with JavaScript?

Spread the love

Sometimes, we want to change property name with JavaScript.

In this article, we’ll look at how to change property name with JavaScript.

How to change property name with JavaScript?

To change property name with JavaScript, we use the delete operator.

For instance, we write

a.prop3 = a.prop1;
delete a.prop1;

to assign a.prop1 to a.prop3.

Then we remove a.prop1 from a with delete.

Conclusion

To change property name with JavaScript, we use the delete operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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