Skip to content
Related Articles

Related Articles

Improve Article

Fabric.js invoke() Method

  • Last Updated : 31 Dec, 2020
Geek Week

The invoke() method is used to perform certain actions like sorting, joining, etc. on the elements of the specified array.

Syntax:

invoke(array, method)

Parameters: This method accepts two parameters as mentioned above and described below:

  • array: This parameter holds the array to iterate over.
  • method: This parameter holds the name of a method to invoke.

Return Value: This method returns the array formed after the given method is applied to it.

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">
            console.log(fabric.util.array
            .invoke([[1, 6, 8], [7, 5, 3],
            [33, 76, 55]], 'sort'));
    </script>
</body>
  
</html>

Output:

[[1, 6, 8], [3, 5, 7], [33, 55, 76]]

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">
        console.log(fabric.util.array
            .invoke([[11, 6, 8], 
            [33, 25, 32]], 'join'));
    </script>
</body>
  
</html>

Output:

["11, 6, 8", "33, 25, 32"]

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up