當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Lodash _.unzip()用法及代碼示例

_.unzip方法類似於_.zip(即,它創建了一個分組元素的數組),除了它接受一個分組元素的數組並且還創建了一個將元素重新分組為其pre-zip配置的數組。

用法:

_.unzip(array)

參數:此方法接受上述和以下描述的單個參數:

  • array (Array):此參數保存要處理的分組元素的數組。

返回值:此方法用於返回重新組合的元素的新數組。

範例1:在這裏,const _ = require(‘lodash’)用於將lodash庫導入文件中。



javascript

// Requiring the lodash library  
const _ = require("lodash");  
      
// Original array  
var zipped = _.zip(['a', 'b'], [1, 2], [true,  
  
false]);     
  
// Use of _.zip()  
// method 
let gfg = _.zip(zipped); 
      
// Printing the output  
console.log(gfg);

輸出:

[ [['a', 1, true], ['b', 2, false]] ]

範例2:

javascript

// Requiring the lodash library  
const _ = require("lodash");  
      
// Original array  
var zipped = (['x', 'y'], [5, 6], [true, false]);     
  
// Use of _.zip()  
// method 
let gfg = _.zip(zipped); 
      
// Printing the output  
console.log(gfg);

輸出:

[ [true, false] ]

注意:該代碼在常規JavaScript中不起作用,因為它需要安裝庫lodash。

相關用法


注:本文由純淨天空篩選整理自shivanisinghss2110大神的英文原創作品 Lodash _.unzip() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。