当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Fabric.js toArray()用法及代码示例


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]




相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js toArray() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。