一、数组的那些事
1、js去除空对象
实例
2、数组去重
(1)、方法1
removalData(arrData) {
const hash = {};
arrData= arrData.reduce(function(item, next) {
//id是你要以什么属性去重
hash[next.id] ? '' : hash[next.id] = true && item.push(next);
return item
}, [])
return arrData;
}
(2)、方法2
newArray.filter(item => !oldArray.some(ele=>ele.id===item.id));
3、ElementUI中获取select的label值
<el-select v-model="value" @change="changeLbale(value)">
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
</el-option>
</el-select>
value = "";
getName = "";
options = [
{
value: "选项1",
label: "黄金糕"
}
]
changeLbale(val){
let obj = {};
obj = this.options.find((item) => {
return item.value === val;
})
this.getName = obj.label;
}