let arr = [1, 3, 7, 24]
{vlan_1: 1, vlan_3: 1, vlan_7: 1, vlan_24: 1}
key
值来满足业务需求:vlan_X
:
let arr = [1,3,7,24]
let param = {}
let res = arr.map(item => {
let key = `vlan_${item}` // 设置成动态的 key 值;
return key
})
console.log(res,2222222222);
map
操作,获取目标对象:
let arr = [1,3,7,24]
let param = {}
arr.map(item => {
let key = `vlan_${item}`
param[key] = 1
})
console.log(param, 11111111);
let arr = [1,3,7,24] // 指定数组:arr;
let param = {} // param 为待生成的对象;
let res = arr.map(item => { // res 为待生成的对象数组;
let key = `vlan_${item}`
let obj = []
param[key] = 1
obj[key] = 1
return obj
})
console.log(param, 11111111);
console.log(res,2222222222);
let arr = [1,3,7,24] // 指定数组:arr;
let param = {} // param 为待生成的对象;
let res = arr.map(item => { // res 为待生成的对象数组;
let key = `vlan_${item}`
let obj = {}
param[key] = 1
obj[key] = 1
return obj
})
console.log(param, 11111111);
console.log(res,2222222222);
let arr = [1,2,3,4,5,5];
let obj = new Set(arr);
console.log(obj); // {1,2,3,4,5}
const arr = ['a', 'b', 'c'];
const obj = Object.assign({}, arr);
console.log(obj); // {0: "a", 1: "b", 2: "c"}
let obj = {"port": "port_0","desc": "desc_0","flag": 0}
let arr = Object.values(obj)
console.log(arr);
其一、哪里有不对或不合适的地方,还请大佬们多多指点和交流!
其二、若有转发或引用本文章内容,请注明本博客地址(直接点击下面 url 跳转
) https://blog.csdn.net/weixin_43405300,创作不易,且行且珍惜!
其三、有兴趣的话,可以多多关注这个专栏(Vue(Vue2+Vue3)面试必备专栏)(直接点击下面 url 跳转
):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482