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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。