Issue
I need to check "Drinks" is already exist in this array if it exists I need to replace the new value instead of the "Drinks:Focus"
["Drinks:Focus", "Baked:No", "Addons:320"]
my angular version
@angular-devkit/architect 0.803.19 (cli-only)
@angular-devkit/build-optimizer 0.0.35
@angular-devkit/core 8.3.19 (cli-only)
@angular-devkit/schematics 8.3.19 (cli-only)
@schematics/angular 8.3.19 (cli-only)
@schematics/update 0.803.19 (cli-only)
rxjs 5.5.6
typescript 2.4.2
webpack 3.12.0
Solution
You can use Array.map()
and String.includes()
to achieve this, as followings:
let arr = ["Drinks:Focus", "Baked:No", "Addons:320"]
arr = arr.map(item => item.includes('Drinks') ? item.replace('Drinks','Beverage') : item)
console.log(arr)
Answered By - Harun Yilmaz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.