Thursday, November 20, 2025
HomeLanguagesJavascriptFabric.js add() Method

Fabric.js add() Method

The add() method is used to add some specified objects into a new collection and returns the newly created collection.

Syntax:

add(...object)

Parameters: This method accepts a parameter as mentioned above and described below:

  • object: This parameter holds the objects to add into a collection.

Return Value: This method returns the newly created collection.

Example 1:

Javascript




<!DOCTYPE html>
 
<html>
 
<head>
   <script src=
   </script>
 
   <script type="text/javascript" src=
   </script>
 
   <script type="text/javascript" src=
   </script>
</head>
 
<body>
   <script type="text/javascript">
    
       // Calling add() function to add its
       // parameters into a collection of objects
       console.log(fabric.Collection.add(1, 2, 3));
       console.log(fabric.Collection.add("a", "b", "c"));
       console.log(fabric.Collection.add("gfg"));
   </script>
 
</body>
 
</html>


Output:

{"_objects":[1,2,3]}
{"_objects":[1,2,3,"a","b","c"]}
{"_objects":[1,2,3,"a","b","c","gfg"]}

Example 2:

Javascript




<!DOCTYPE html>
 
<html>
 
<head>
   <script src=
   </script>
 
   <script type="text/javascript" src=
   </script>
 
   <script type="text/javascript" src=
   </script>
</head>
 
<body>
   <script type="text/javascript">
    
       // Specifying some objects
       var obj1 = {name: "GFG"};
       var obj2 = {Department: "Computer Science"};
       console.log(fabric.Collection.add(obj1, obj2));
   </script>
 
</body>
 
</html>


Output:

{"_objects":[{"name":"GFG"},{"Department":"Computer Science"}]}
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
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6904 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS