Fabric.js toArray() Method
Last Updated :
01 Apr, 2021
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 >
< 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 >
< 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]
Share your thoughts in the comments
Please Login to comment...