Fabric.js中的toArray()方法用于将指定的array-like对象转换为数组。这可用于将参数列表或NodeList转换为数组。
用法:
toArray( arrayLike )
参数:此方法接受如上所述和以下描述的单个参数:
- arrayLike:此参数保存指定的array-like个对象。
 
返回值:此方法返回转换后的数组。
范例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>输出:
[] [] [1,2,3,4] ["a"] ["a"] ["a","b","c"]
范例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"> 
      
        // Specifing 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>输出:
[] [] [] [1,2,3,4]
相关用法
- JQuery Misc toArray()用法及代码示例
 - Lodash _.toArray()用法及代码示例
 - Collect.js toArray()用法及代码示例
 - PHP Ds\Collection toArray()用法及代码示例
 - PHP Ds\Vector toArray()用法及代码示例
 - PHP Ds\Deque toArray()用法及代码示例
 - PHP SplFixedArray toArray()用法及代码示例
 - PHP Ds\Pair toArray()用法及代码示例
 - Underscore.js _.toArray()用法及代码示例
 - Lodash _.method()用法及代码示例
 - Node.js Http2ServerRequest.method用法及代码示例
 - Node.js http.IncomingMessage.method用法及代码示例
 - Javascript dataView.getInt16()用法及代码示例
 - Javascript RegExp toString()用法及代码示例
 - Node.js URLSearchParams.has()用法及代码示例
 - JavaScript Math cosh()用法及代码示例
 - HTML DOM isEqualNode()用法及代码示例
 - JavaScript Date toLocaleTimeString()用法及代码示例
 - Node.js crypto.createHash()用法及代码示例
 - Node.js writeStream.clearLine()用法及代码示例
 - Javascript Number isSafeInteger()用法及代码示例
 - Node.js fs.link()用法及代码示例
 
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js toArray() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
