Fabric.js toArray() Method
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 = "https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" > </ 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 = "https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" > </ 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]