Underscore.js 是一個 JavaScript 庫,它使對數組、字符串、對象的操作變得更加容易和方便。 _.isSet() 函數用於檢查給定對象是否是 javascript 設置的。鏈接 underscore.js CDN 時,“_” 作為全局變量附加到瀏覽器。
用法:
_.isSet(object);
參數:
- object: 它是任何 JavaScript 對象,例如數組、字符串、映射、集合等。
返回:它返回布爾值。如果對象是 JavaScript 集,則函數返回 true,否則返回 false。
為了更好地理解該函數,下麵給出了一些示例。
注意:在瀏覽器中運行代碼之前需要鏈接UnderScore.js的CDN。
示例 1:當給定 Set 時,輸出為 True。
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charMap="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script>
//creating a set using constructor
var obj= new Set();
//using the underscore.js function _.isSet()
var isSet= _.isSet(obj);
console.log(isSet)
//If the given object is Set it prints the object is set
if(isSet)
console.log(`The ${obj} is the Set of Javascript.`)
else
console.log(`The ${obj} is not the Set of Javascript.`)
</script>
</body>
</html>
輸出:
示例 2:當給定一個數組時,它返回 False。
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charMap="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script>
//creating a array of size 2 using constructor
var obj= new Array(2);
//filling array with value 10
obj.fill(10);
//using the underscore.js function _.isSet()
var isSet= _.isSet(obj);
console.log(isSet)
//If the given object is Set it prints the object is Set.
if(isSet)
console.log(`The ${obj} is the Set of Javascript.`)
else
console.log(`The ${obj} is not the Set of Javascript.`)
</script>
</body>
</html>
輸出:
相關用法
- underscore.js _.isSet()用法及代碼示例
- underscore.js _.isSequential()用法及代碼示例
- underscore.js _.isSymbol()用法及代碼示例
- underscore.js _.isRegExp()用法及代碼示例
- underscore.js _.isFinite()用法及代碼示例
- underscore.js _.isNaN()用法及代碼示例
- underscore.js _.isUndefined()用法及代碼示例
- underscore.js _.isDate()用法及代碼示例
- underscore.js _.isWeakSet()用法及代碼示例
- underscore.js _.isAssociative()用法及代碼示例
- underscore.js _.isDecreasing()用法及代碼示例
- underscore.js _.isEven()用法及代碼示例
- underscore.js _.isFloat()用法及代碼示例
- underscore.js _.isIncreasing()用法及代碼示例
- underscore.js _.isIndexed()用法及代碼示例
- underscore.js _.isInstanceOf()用法及代碼示例
- underscore.js _.isInteger()用法及代碼示例
- underscore.js _.isJSON()用法及代碼示例
- underscore.js _.isNumeric()用法及代碼示例
- underscore.js _.isPositive()用法及代碼示例
- underscore.js _.isZero()用法及代碼示例
- underscore.js _.isOdd()用法及代碼示例
- underscore.js _.isNegative()用法及代碼示例
- underscore.js _.isTypedArray()用法及代碼示例
- underscore.js _.isArrayBuffer()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 Underscore.js _.isSet() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。