Open In App

Fabric.js toArray() Method

Last Updated : 01 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The toArray() method in Fabric.js is used to convert the specified array-like objects to an array. This can be used to convert an arguments list or a NodeList to an array. 

Syntax:

toArray( arrayLike )

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

  • arrayLike: This parameter holds the specified array-like objects.

Return Value: This method returns the converted array.

Example 1:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
     
        // Calling toArray() function over
        // some specified array-like objects
        console.log(fabric.util.toArray(1));
        console.log(fabric.util.toArray(1, 2));
        console.log(fabric.util.toArray([1, 2, 3, 4]));
        console.log(fabric.util.toArray("a"));
        console.log(fabric.util.toArray("a", "b"));
        console.log(fabric.util.toArray(["a", "b", "c"]));
    </script>
</body>
 
</html>


Output:

[]
[]
[1,2,3,4]
["a"]
["a"]
["a","b","c"]

Example 2:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
     
        // Specifying some array-like objects
        var number1 = 0;
        var number2 = 123;
        var number3 = (1, 2);
        var number4 = [1, 2, 3, 4];
 
        // Calling toArray() function over
        // the above specified array-like objects
        console.log(fabric.util.toArray(number1));
        console.log(fabric.util.toArray(number2));
        console.log(fabric.util.toArray(number3));
        console.log(fabric.util.toArray(number4));
    </script>
</body>
 
</html>


Output:

[]
[]
[]
[1,2,3,4]


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads