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
259 views
in Technique[技术] by (71.8m points)

javascript - Getting extra bullet in return split and map

I'm getting extra empty bullet using this global function. I want to next line the strings from the object and layout or return in bulleted enter image description here

Here's the data

{ 
  target: '● Participates in technical discussions, suggesting possible options for designs and best practices ● Answers customer inquiries promptly',
}

Here's my code

export function formatString(text) {
 const newText = text.split('●').map(str => <p>● {str}</p>);
 return newText;
}

Applying it to another component and passing the parameter formatString(target)


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

1 Answer

0 votes
by (71.8m points)

Before the first bullet point, there is an empty string. Slice the array.

export function formatString(text) {
 const newText = text.split('●').slice(1).map(str => <p>● {str}</p>);
 return newText;
}

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

...