Javascript - Remove 1st character from each line
Javascript - Remove 1st character from each line
CODE
<!--JQuery Reference Library-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script>
function remove1stCharacter(){
inputText = "Apple\nBanana\nOrange"; // Provide the input text here.
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).substring(1)); //Remove the 1st character from each line.
});
var result = resultArray.join("\r\n"); //Join all the array elements with a new line character.
alert(result);
}
remove1stCharacter();
//Output
//pple
//anana
//range
</script>
Comments
Post a Comment