_.invert()函數用於返回對象的副本,其中對象鍵已轉換為值,而對象值已轉換為鍵。這意味著對象的[鍵,值]是反向的。
用法:
_.invert( object )
參數:該函數接受上述和以下描述的單個參數:
- object:它包含對象元素,該對象元素包含鍵和值對的元素。
返回值:它以相反的[value,key]順序返回對象的[key,value]。
範例1:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script type="text/javascript">
var obj = {
Company:"GeeksforGeeks",
Address:"Noida",
Contact:"+91 9876543210",
Email:"abc@gfg.com"
}
console.log(_.invert(obj));
</script>
</body>
</html>
輸出:
範例2:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script type="text/javascript">
var inv = _.invert({
num1:10,
num2:20,
num3:30,
num4:40
});
console.log(inv);
</script>
</body>
</html>
輸出:
相關用法
- d3.js d3.continuous.invert()用法及代碼示例
- CSS invert()用法及代碼示例
- d3.js pow.invert()用法及代碼示例
- d3.js log.invert()用法及代碼示例
- d3.js time.invert()用法及代碼示例
- d3.js transform.invert()用法及代碼示例
- Lodash _.invert()用法及代碼示例
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
注:本文由純淨天空篩選整理自AshokJaiswal大神的英文原創作品 Underscore.js | _.invert() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。