Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

javascript - Adding text to beginning of each array element

I have an array which contains the contents as follows:

["ZS125-48ATab", "STR125YBTab", "KS125-24Tab", "ZS125-50Tab", "DFE125-8ATab", "ZS125-30Tab", "HT125-8Tab", "HT125-4FTab", "STR50Tab"] 

Is it possible to append a # symbol to the front of each element in the array.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Example for ES6

var arr = ['first', 'second', 'third'];    
arr = arr.map(i => '#' + i);

Result:

console.log(arr); // ["#first", "#second", "#third"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...