Backbone.js unset Model

In this article, we will see the Backbone.js unset model. The Backbone.js unset model is used to unset or remove the value from the attributes in a given model.
Syntax:
Backbone.Model.unset(attribute);
Note: It takes one parameter.
- attribute: specifies the attribute in a model to be unsettled.
Example 1: In this example, we will unset the bookid attribute in a book model
HTML
<!DOCTYPE html> <html>   <head>         type="text/javascript">     </script>     <script src=         type="text/javascript">     </script>     <script src=         type="text/javascript">     </script>       <script type="text/javascript">         var Books = Backbone.Model.extend();         var book = new Books({             bookid: 23,             price: 678,             book_name: 'php'         });           document.write("bookid: ", book.get('bookid'));                   // Unset the bookid         book.unset('bookid');         document.write("<br>")           document.write("bookid: ", book.get('bookid'));     </script> </head>   <body></body>   </html> |
Output:
bookid: 23 bookid: undefined
Example 2: In this example, we will unset the price attribute in a book model
HTML
<!DOCTYPE html> <html>   <head>         type="text/javascript"></script>     <script src=         type="text/javascript"></script>     <script src=         type="text/javascript"></script>       <script type="text/javascript">         var Books = Backbone.Model.extend();         var book = new Books({             bookid: 23,             price: 678,             book_name: 'php'         });           document.write("price: ", book.get('price'));           // Unset the bookid         book.unset('price');         document.write("<br>")           document.write("price: ", book.get('price'));     </script> </head>   <body></body>   </html> |
Output:
price: 678 price: undefined
Reference: https://backbonejs.org/#Model-unset
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



