0

how can i parse an input string in JavaScript ? ,and by parsing I mean parsing of a string character by character. i don't want to use any inbuilt methods. use of for loop will be helpful. i have tried a palindrome function on an integer number by using modulus of a number but not sure how to do this in a string

    enter code here
var str = "the quick brown fox jumps over a lazy dog";
 for (i=0; i<str.length;i++){
//the code goes here//
}

help me with a function which can be used in different programs to parse strings. i am new to programming and stackoverflow . i'll try to get better with time

3
  • what do you want to do with the string ? Commented Oct 3, 2017 at 10:31
  • actually i want to create a palindrome function which first parse the whole string and then reverses it . i am familliar with the javascript reverse method but if i be able to do without it that would be great Commented Oct 3, 2017 at 10:33
  • You could use the index of the for loop to access characters in the string one at a time and do whatever you want with it. Like var character = str.split('')[i]; Commented Oct 3, 2017 at 10:33

1 Answer 1

1

I mean parsing of a string character by character.

I am guessing you're wanting to go through the characters. You can do the following

var str = "the quick brown fox jumps over a lazy dog";
for (i=0; i<str.length;i++){
    var letter = str[i] // use this to implement your palindrome logic
    console.log(letter); // each letter will be printed individually
}

Think of strings as an array of characters. So you'd index your way out similar to how you'd do with an array.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks,i think i can push each letter in an array too with this,and then can play with the string better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.