Saturday, July 4, 2026
HomeLanguagesJavascriptBackbone.js clear Model

Backbone.js clear Model

In this article, we will discuss Backbone.js clear model. The Backbone.js clear model is used to clear or remove all the existing attributes from the given model. The attributes will be set to undefined.

Syntax:

Backbone.Model.clear(options)

Parameters: It accepts a single parameter.

  • options: This parameter defines the parameters like id, name, and others (removed from the model).

Example 1: In this example, we will clear the book_name attribute that has already value, so we are clearing or removing the book_name value.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
    <script type="text/javascript" src=
    </script>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var Books = Backbone.Model.extend();
        var book = new Books(
          { book_name: "HTML", price: 100 }
        );
        document.write(
          "Actual Attribute:  ",
          book.get('book_name')
        );
        document.write("<br>");
  
        // Using the clear() method
        book.clear();
        document.write(
          "Attribute after Clear: ",
          book.get('book_name')
        );
    </script>
</body>
  
</html>


Output:

Actual Attribute: HTML
Attribute after Clear: undefined

Example 2: In this example, we will clear the price attribute that has already value, so we are clearing or removing the price value.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
    <script type="text/javascript" src=
    </script>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var Books = Backbone.Model.extend();
        var book = new Books(
          { book_name: "HTML", price: 100 }
        );
        document.write(
          "Actual Attribute:  ",
          book.get('price')
        );
        document.write("<br>");
  
        // Using the clear() method
        book.clear();
        document.write(
          "Attribute after Clear: ",
          book.get('price')
        );
    </script>
</body>
  
</html>


Output:

Actual Attribute: 100
Attribute after Clear: undefined

Reference: https://backbonejs.org/#Model-clear

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

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS