Your second "for" loop


Second for loop isn't pushing values

var text="Hey yash how are you/ party?";
var myName="yash";
var hits=[];
for(var i=0; i<text.length; i+=1){
    if(text[i]=== 'y'){
        for(var j=i;j< (i+myName.length); j++){


Try replacing the contents of the for loop with sometime to push j to the array hits. hits.push(text[j])


j contains the indexes of your name stored in text, so you can use text[j] to get the letters. That is what you should push into your hits array. (you created the array for this purpose)


Can you please edit the code and show me?


can you show an updated version of your code? So we can help you further


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.