Skip to content
Related Articles

Related Articles

Fabric.js add() Method
  • Last Updated : 05 Jan, 2021

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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">
     
       // Specifing some objects
       var obj1 = {name: "GFG"};
       var obj2 = {Department: "Computer Science"};
       console.log(fabric.Collection.add(obj1, obj2));
   </script>
  
</body>
  
</html>

chevron_right


Output:

{"_objects":[{"name":"GFG"},{"Department":"Computer Science"}]}

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :