[英]Remove specific property from an array of object
I have issue with splicing item from an array object with specific property.
我在从具有特定属性的数组对象中拼接项目时遇到问题。 Here is the explanation.
这是解释。
delColumn($event: any, el: any) {
if ($event.target && el > -1) {
var colId: string = this.receivedData[0].value.columns[el].id;
var obj = this.receivedData[0];
obj.values.columns = obj.values.columns.filter(s => s.id != colId);
obj.values.rows.forEach(s => {
delete s.Col_1;
return s;
});
}
} }
Now, My requirement is When I click on Delete Column it comes into this method and I want to delete specific column and rows associated with that.现在,我的要求是当我单击“删除列”时,它会进入此方法,并且我想删除与之关联的特定列和行。
Thanks for the help in advance.提前感谢您的帮助。
rows=[{Col1:1,Value:1},
{Col1:1,Value:2},
{Col1:1,Value:3},
{Col1:1,Value:4}];
rowsNew=this.rows.map(x=>{
return this.objectWithoutKey(x,"Col1");
})
objectWithoutKey(object, key){
const {[key]: deletedKey, ...otherKeys} = object;
return otherKeys;
}
ngOnInit()
{
console.log(this.rows);
console.log(this.rowsNew);
}
Use filter
and forEach
使用
filter
和forEach
obj.values.columns = obj.values.columns.filter(s => s.id != "Col_1");
obj.values.rows.forEach( s => {
delete s.Col_1;
return s;
});
I have created NPM package for this type of problems 我已经为此类问题创建了NPM软件包
Please refer to this:- https://www.npmjs.com/package/array-refactor 请参考: -https : //www.npmjs.com/package/array-refactor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.