I have a string array with strings like age ,gender,nationality. Need to replace age to agexxxx. So is there any method to replace a string in string array on angular?
this.segment=['age','Nationality','gender'];
Here you go :
var segment=['age','Nationality','gender'];
var changed = segment.map(seg => seg.replace('age', 'agexx') );
console.log('Original --->' ,segment);
console.log('Changed --->' ,changed);
let a = ['age','hello','world']
a.splice(0, 1,'agexxx');
alert(a)
reference : Array.prototype.splice
['age','Nationality','gender'].map(w => w === 'age' ? 'agexxxx' : w);If you want to modify the existing array, you can useforEachinstead ofmap.