SlideServe
Menu
Préférences
© SlideServe · v2026

JavaScript Strings and Arrays

gdurden avatar
18 diapositives · 436 Views · Jan 04, 2020

Learn about how strings and arrays work in JavaScript, including indexing, methods, and properties. Master the essential skills for manipulating strings and arrays effectively in your code.

JavaScript Strings and Arrays - slide 1
01 / 18JavaScript Strings and Arrays
1 / 17

Télécharger la présentation

JavaScript Strings and Arrays
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. JavaScript Strings and Arrays Kevin Harville

  2. Strings and Arrays • Strings are indexed groups of CHARACTERS. • Arrays are indexed groups of numbers. • Therefore we can refer to a particular number or letter by referring to its index.

  3. Array Examples • I could have an array of images: • myImage[1] = “myDog.jpg” • myImage[2] = “myCat.jpg” • myImage[3] = “myFish.jpg” • Or an array of the students’ scores: • classScore[0] = 100 • classScore[1] = 95 • classScore[2] = 86

  4. Strings and Arrays • Strings and Arrays are objects rather than variables. • Objects have properties and methods • myString = “Kevin” makes it look like a variable, but is actually a shortcut to make strings easy to use. • IMPORTANT: Strings and Arrays are indexed, or counted, starting at 0, not 1.

  5. String Properties • myString.length

  6. String Methods • String objects have several useful methods: • myString.toLowerCase(); • myString.toUpperCase(); • Others Follow…

  7. String Methods: Substring • myString.substring(start, end+1); • “Kevin”.substring(0,2) returns “Ke” • “Kevin”.substring(1,3) returns “ev” • REMEMBER: ARRAYS START AT ZERO!

  8. String Methods: charAt • charAt returns the value of the character at an index position: • “Kevin”.charAt(4) returns “n”why “n”?

  9. String Methods: indexOf • “Kevin”.indexOf(“vi”) returns 2 • indexOf returns –1 if it is not found:Kevin.indexOf(“Joe”) returns –1 • You can specify the starting position:“Rin Tin Tin”. indexOf(“in”, 4) returns 5 • To find multiple occurrences repeat the process.

  10. String Methods: lastIndexOf • Same as indexOf, but starts searching from the end.

  11. String Methods: Split • This method creates an arraymyNewStrings = “Quick Brown Fox”.Split(“ “); • myNewStrings[0] = “Quick”myNewStrings[1] = “Brown”myNewStrings[2] = “Fox”

  12. Some Other String Methods: • .replace (4.0 Browsers or higher) • HTML functionality, such as • .fontcolor • .fontsize • .strike • .etc.

  13. Arrays • Again, an array is a group of indexed values. • For instance, instead of having individual class scores Score1, Score2, etc, you can have score[0], score[1]…score[30]. • So, What’s the difference?

  14. Arrays • The difference is that the indexes can themselves be referred to by a variable! score[x] = 7 score[x + 1] = 4 score[y]= 9

  15. Arrays • When we want a group of related data, we may declare an Array object: myArray = new Array(50) This would set up 50 elements, from 0 to 49. There is no 50th element.

  16. Arrays • That indexing ability makes keeping track of related data very easy. Name[7] = “Fred” Lab1[7] = 5 Lab2[7] = 4 Midterm[7] = 12

  17. Array Object: Sort Method • Using the sort method, you can sort a numeric or alphabetic array. • MyArray.sort()

  18. Summary • Strings and arrays are used in most scripts • Learning them is necessary and a useful programming skill.