Advertisement
maramizo

Untitled

Jun 21st, 2020
1,761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Lets say you have an array that has a bunch of websites names as you can see below.
  2. //All of them start with www. and you want to remove that part, so that 'www.google.com' -> 'google.com'
  3.  
  4. var websites = ['www.google.com', 'www.facebook.com', 'www.twitter.com'];
  5. function removeWWW(webArray){
  6.     for(i=0;i<webArray.length;i++)
  7.     {
  8.         webArray[i] = webArray[i].substr(4, webArray[i].length-4);
  9.         //webArray[i] =
  10.         //This part loops through the entire array
  11.  
  12.         //webArray[i].substr
  13.         //substr is a function that means SUB STRING, which cuts up a string into pieces.
  14.         //for example, var x = 'hello', x.substr(1, 4) is 'ello'.
  15.         //substr(starting character, how many characters to include from that character)
  16.         //so in the example, x[0] is 'h', x[1] is 'e' (so 1,4 means that it starts from 'e'
  17.         //and includes 4 characters, 'e' 'l' 'l' 'o'.
  18.  
  19.         //in our example, it starts from the fifth character, in 'www.google.com' its the 'g'
  20.         //and includes all of the rest of the string (since it starts from the 4th, so length - 4 means includes all the remaining
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement