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


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


removeFromArray()方法用于从指定的值数组中删除一个值。

用法:

removeFromArray(array, value)

参数:此方法接受上面提到和下面描述的两个参数:

  • array:此参数保存指定的值数组。
  • value:此参数保存将要从数组中删除的值。

返回值:此方法返回剩余值的数组。

范例1:



Javascript

<!DOCTYPE html>
 
<html>
 
<head>
    <script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
    </script>
 
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map">
    </script>
 
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js">
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        // Calling removeFromArray() function over
        // some specified arrays and values to be removed
        console.log(fabric.util.removeFromArray([1, 2, 3], 2));
        console.log(fabric.util.removeFromArray([1, 2, 3], 1));
        console.log(fabric.util.removeFromArray([1, 2, 3], 0));
    </script>
</body>
 
</html>

输出:

[1,3]
[2,3]
[1,2,3]

范例2:

Javascript

<!DOCTYPE html>
 
<html>
 
<head>
    <script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
    </script>
 
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map">
    </script>
 
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js">
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        // Specifying some arrays
        var array1 = [2, 4, 6];
        var array2 = [1, 3, 4];
 
        // Specifying some values
        var value1 = 2;
        var value2 = 4;
 
        // Calling removeFromArray() function over the
        // above specified arrays and values to be removed
        console.log(fabric.util.removeFromArray(array1, value1));
        console.log(fabric.util.removeFromArray(array2, value2));
    </script>
</body>
 
</html>

输出:

[4,6]
[1,3]

相关用法


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