Javascript – Play with strings and arrays

Last weekend I was playing with strings in Javascript and I made different exercises with them, so this is a good moment to write a remember post with this simple commands.

Exercise 1: Discard first n characters of a string, in this case 3

Exercise 2: Get the string until certain character, in this case we will get all the characters before “&”


Exercise 3:
Get the string after certain character, in this case we will get all after “&” skipping first 5 characters

Exercise 4: Select character in certain position. How to select the third character, take in mind we have to start counting first element with 0, for this reason 2 will be the third.

Exercise 5: Convert string into array, In this case we will split a string into array using existing spaces as separators ” ”

Exercise 6: Select element inside Array, in this case we will select the second element.

Exercise 7: Select 2 element inside Array, in this case we will select the second and the third element.

Exercice 8: Create an array splitting every charecter

Exercise 9: Split string into array, convert elements into integers and sum all the items

Exercise 10: Capitalize or Decapitalize an existing string. Sometimes you want to avoid case sensitive problems and a good way to do that is capitalize or decapitalize stings

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.