JavaScript - Add Characters at the end of each line
Javascript - Add Characters at the end of each line. This program adds some characters at the end of each line of the input text.
CODE
<!--JQuery Reference Library-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script>
function addCharactersEnd(){
inputText = "Apple\nBanana\nOrange"; // Provide the input text here.
characters = "$$$"; // Provide the characters to add at the end of each line.
var lines = inputText.split("\n"); //Split the input based on the new line character.
var resultArray = [];
//Loop through the splitted lines.
$.each(lines, function(){
resultArray.push(String(this) + characters); //For each line, add characters at the end and push it to the output array.
});
var result = resultArray.join("\r\n"); //Join all the array elements with a new line character.
alert(result);
}
addCharactersEnd();
//Output
//Apple$$$
//Banana$$$
//Orange$$$
</script>
Comments
Post a Comment