Saturday, November 15, 2025
HomeLanguagesJavascriptBackbone.js unset Model

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>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"
        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>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"
        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, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS