Last post May 17, 2020 04:16 PM by bruce (sqlwork.com)
Member
41 Points
376 Posts
May 17, 2020 07:41 AM|ahmedbarbary|LINK
problem How to remove item if exist before and add current as new ?
I need when add statusdate exist before on collectfulldata then remove exist and and add new one and if not exist add it .
meaning i dont need two statusdata with same name exist two time . and if statusdata not exist add it .
initcollectdropdowslist=[]; collectfulldata:string; let textdata=$event.target.options[$event.target.options.selectedIndex].text; let statusdata:any = this.FilterBinddata.filter(s=>s.reportSource==textdata)[0].reportSource2; this.collectfulldata= statusdata + "=" + "'" + textdata + "'"; this.initcollectdropdowslist.push(this.collectfulldata); console.log("full data is " + this.initcollectdropdowslist)
current result full data is Text5='Lifecycle',Text6='Package',Text7='Parametric'
Expected result if add Text8='car' to collectfulldata add it because not exist if add Text6='OBS' add it but remove exist as Text6='Package'
All-Star
58474 Points
15793 Posts
May 17, 2020 04:16 PM|bruce (sqlwork.com)|LINK
This logic would make more sense as a mapped object (dictionary) rather than array, but the fix is simple. Just check if it exists
const index = this.initcollectdropdowslist.findIndex(e => e.startsWith(statusdata+"="));
If the index is not -1you can replace or remove with a slice()
Member
41 Points
376 Posts
How to remove item if exist before and add current as new ?
May 17, 2020 07:41 AM|ahmedbarbary|LINK
problem
How to remove item if exist before and add current as new ?
I need when add statusdate exist before on collectfulldata then remove exist and and add new one
and if not exist add it .
meaning i dont need two statusdata with same name exist two time .
and if statusdata not exist add it .
current result
full data is Text5='Lifecycle',Text6='Package',Text7='Parametric'
Expected result
if add Text8='car' to collectfulldata add it because not exist
if add Text6='OBS' add it but remove exist as Text6='Package'
All-Star
58474 Points
15793 Posts
Re: How to remove item if exist before and add current as new ?
May 17, 2020 04:16 PM|bruce (sqlwork.com)|LINK
This logic would make more sense as a mapped object (dictionary) rather than array, but the fix is simple. Just check if it exists
If the index is not -1you can replace or remove with a slice()