Lodash _.zipObject()实例讲解
时间:2022-04-07 <iframe data-google-container-id="a!1" data-google-query-id="CNnr4s683IIDFeBRDwId4OoDAA" data-load-complete="true" frameborder="0" height="90" id="aswift_0" marginheight="0" marginwidth="0" name="aswift_0" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9401041403549801&output=html&h=90&slotname=4032144190&adk=909515367&adf=577686739&pi=t.ma~as.4032144190&w=728&fwrn=4&fwrnh=100&lmt=1700823320&rafmt=12&format=728x90&url=http%3A%2F%2Fwww.manongjc.com%2Fdetail%2F30-pemabiujfqrociw.html&ea=0&fwr=0&fwrattr=true&rh=90&rw=728&sfro=1&wgl=1&dt=1700823320044&bpp=4&bdt=642&idt=504&shv=r20231109&mjsv=m202311150101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D66929359d7b51db8%3AT%3D1697526713%3ART%3D1697526713%3AS%3DALNI_MbZZmSH-5NbxeMNnbJq0mFx8ozulg&gpic=UID%3D00000c6507049f05%3AT%3D1697526713%3ART%3D1697526713%3AS%3DALNI_MZ1L8iuy4v9UgUe-qLc5-892BzvKg&correlator=390031886269&frm=20&pv=2&ga_vid=1100761339.1700823321&ga_sid=1700823321&ga_hid=1603812906&ga_fc=0&u_tz=480&u_his=1&u_h=864&u_w=1536&u_ah=816&u_aw=1536&u_cd=24&u_sd=1.25&adx=211&ady=307&biw=1473&bih=708&scr_x=0&scr_y=159&eid=44759876%2C44759927%2C42532605%2C31079606%2C44798934%2C44809003%2C44809317%2C31078297%2C31079757%2C44806139%2C44807764%2C44808149%2C44808284%2C44809056&oid=2&pvsid=2707106113394072&tmod=46840308&wsm=1&uas=0&nvt=1&ref=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DBK0HlliY43_KLw6CQg_5vZWXNqENQdBmljR5B-BkOeiu6vUv-HUE0Id95TxJTityb2Lk9KyJl_49BC7gjGtt0_%26wd%3D%26eqid%3Db51f1287001a6d480000000465608115&fc=896&brdim=-1%2C-1%2C-1%2C-1%2C1536%2C0%2C1538%2C818%2C1488%2C708&vis=1&rsz=%7C%7CpoeE%7C&abl=CS&pfx=0&fu=128&bc=23&psd=W251bGwsbnVsbCxudWxsLDNd&ifi=1&uci=a!1&fsb=1&dtd=522" width="728"></iframe> 本文章向大家介绍Lodash _.zipObject()实例讲解,主要分析其语法、参数、返回值和注意事项,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。 <iframe data-google-container-id="a!2" data-google-query-id="CPzc48683IIDFQBVDwIdUDAE1g" data-load-complete="true" frameborder="0" height="90" id="aswift_1" marginheight="0" marginwidth="0" name="aswift_1" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9401041403549801&output=html&h=90&slotname=1516503570&adk=61531810&adf=3996677496&pi=t.ma~as.1516503570&w=728&lmt=1700823320&rafmt=12&format=728x90&url=http%3A%2F%2Fwww.manongjc.com%2Fdetail%2F30-pemabiujfqrociw.html&ea=0&wgl=1&dt=1700823320048&bpp=1&bdt=646&idt=523&shv=r20231109&mjsv=m202311150101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D66929359d7b51db8%3AT%3D1697526713%3ART%3D1697526713%3AS%3DALNI_MbZZmSH-5NbxeMNnbJq0mFx8ozulg&gpic=UID%3D00000c6507049f05%3AT%3D1697526713%3ART%3D1697526713%3AS%3DALNI_MZ1L8iuy4v9UgUe-qLc5-892BzvKg&prev_fmts=728x90&correlator=390031886269&frm=20&pv=1&ga_vid=1100761339.1700823321&ga_sid=1700823321&ga_hid=1603812906&ga_fc=0&u_tz=480&u_his=1&u_h=864&u_w=1536&u_ah=816&u_aw=1536&u_cd=24&u_sd=1.25&adx=211&ady=516&biw=1473&bih=708&scr_x=0&scr_y=159&eid=44759876%2C44759927%2C42532605%2C31079606%2C44798934%2C44809003%2C44809317%2C31078297%2C31079757%2C44806139%2C44807764%2C44808149%2C44808284%2C44809056&oid=2&pvsid=2707106113394072&tmod=46840308&wsm=1&uas=0&nvt=1&ref=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DBK0HlliY43_KLw6CQg_5vZWXNqENQdBmljR5B-BkOeiu6vUv-HUE0Id95TxJTityb2Lk9KyJl_49BC7gjGtt0_%26wd%3D%26eqid%3Db51f1287001a6d480000000465608115&fc=896&brdim=-1%2C-1%2C-1%2C-1%2C1536%2C0%2C1538%2C818%2C1488%2C708&vis=1&rsz=%7C%7CpoeE%7C&abl=CS&pfx=0&fu=256&bc=23&psd=W251bGwsbnVsbCxudWxsLDNd&ifi=2&uci=a!2&fsb=1&dtd=527" width="728"></iframe>_.zipOnject()方法用于将两个数组组合为一个对象,一个数组作为键,另一个作为值。
用法:
_.zipObject([props=[]], [values=[]])
参数:该方法接受上述和以下所述的两个参数:
- [props = []](数组):此参数保存属性标识符。
- [values = []](数组):此参数保存属性值。
返回值:此方法重新调整一个对象,该对象包含与给定数组相对应的键值。
范例1:
const _ = require('lodash');
let x = ['a', 'b', 'c'];
let y = [1, 2, 3]
let obj = _.zipObject(x, y)
console.log(obj);
这里,const _ = require('lodash')
用于将lodash库导入文件中。
输出:
{ a:1, b:2, c:3 }
范例2:
const _ = require('lodash');
let x = ['name', ';language', 'used'];
let y = ['lodash', 'JavaScript', 'nodejs']
let obj = _.zipObject(x, y)
console.log(obj);
输出:
{ name:'lodash', ';language':'JavaScript', used:'nodejs' }
范例3:如果您传递一个额外的键并且没有值,它将放置与该键关联的未定义值。
const _ = require('lodash');
let x = ['a', 'b', 'c', 'd'];
let y = [1, 2, 3]
let obj = _.zipObject(x, y)
console.log(obj);
输出:
{ a:1, b:2, c:3, d:undefined }
范例4:如果您传递一个额外的值并且没有 key ,它将忽略该值。
const _ = require('lodash');
let x = ['a', 'b', 'c'];
let y = [1, 2, 3, 4]
let obj = _.zipObject(x, y)
console.log(obj);
输出:
{ a:1, b:2, c:3 }
注意:在正常的JavaScript中这将无法正常工作,因为它需要安装库lodash。
参考: https://lodash.com/docs/4.17.15#zipObject
标签:obj,lodash,_.,let,const,zipObject,Lodash From: https://www.cnblogs.com/sexintercourse/p/17854538.html