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