7. JS Strings data type Público

7. JS Strings data type

Kostas Diakogiannis
Curso por Kostas Diakogiannis, atualizado more than 1 year ago Colaboradores

Descrição

Introduction to properties and methods of strings data type in JS

Informações do módulo

Sem etiquetas

Contexto

Course's Objectives 1. Understand the JS string's data type. 2. Learn how to concatenate string literals, or even injecting JavaScript expressions inside strings by using the new string interpolation syntax. 2. Learn about the string length property, and how to access a specific character from a string. 3. Perform other actions like splitting a string into an array and more. 4. Find out how to slice a part of a string or convert it to lower case.  5. Learn the useful built-in string methods that JS offer in order to manipulate strings.
Mostrar menos
Sem etiquetas

Contexto

String concatenation vs string interpolation The + operator, when one or more of the parts is a string acts like a string concatenating operator. Unites 2 strings in one. Take care of the space you must literally give. This works well if you have string literals.  In case of string interpolation you don't have to. You can put all assignments and variables inside a string.
Mostrar menos
Sem etiquetas

Contexto

String methods and properties Strings can have methods and properties exactly like objects.  One of the commonest properties is the length property who returns the length of a string and how many characters this string is comprised of. Another important method is the  split method. That splits actually a string into a smaller strings, and then it puts them as elements into an array. The new array is comprised of string elements and you can work individually with every substring. Split is a method, that means that you can also pass an argument and specify every WHICH character occurrence you want  to split your main string. For example if you have a string like: let sentence = 'this sentence is nonsense', sentence.split('') // Splits every single character into an array. ['t', 'h', 'i', 's', ' ', 's', 'e', 'n', 't'] etc. sentence.split(' ') (with a space inside the argument. Splits every time it finds a space. So we end up with something like. ['this', 'sentence', 'is', 'nonsense'].   Find out all methods for strings here.
Mostrar menos
Sem etiquetas

Contexto

S-1 Find the biggest word in a sentence Create a big sentence and save this string into a variable.  Try to find out how you are going to print out the biggest word in this string. step1 hint: Maybe you would like to split the string into separable pieces and have every word separately. step2 hint: When you do this maybe you want to loop through each word and compare length with the next one.
Mostrar menos
Sem etiquetas

Contexto

Working with arrays and strings Strings can also work well with arrays. If you want to take a string and split every letter into an array in order to work individually with all letters you can do it with the split method as we have seen. Join method is the exact opposite. Is an ARRAY METHOD actually that unites all the elements of an array into a string. You can parameterize what is going to stand between every array element when the string unification takes place exactly the same way with a split, by adding something between every substring. example: const fruits = ['Apple', 'Orange', 'Bananas']. If we put fruits.join('-') all elements will be unified in a single string with '-' between them.  Final result: 'Apple-Orange-Bananas'  Reverse is another action that can be taken in ARRAY to reverse the order of the elements inside it.  Returns the array in reversed order. Let's see some case were we can used what we learned.
Mostrar menos
Sem etiquetas

Contexto

S-2 Find Palindrome Write a function that accepts a name (as a string) and returns a message if this name is  a palindrome or not. It's better before start comparing the two strings to put both to lower case, in order to avoid case sensitivity problems. You may want to revisit some of the strings and arrays methods you learned in order to solve this. *Palindrome is a string that if you reverse it, is read the same' for ex. 'anna' is a palindrome.
Mostrar menos
Sem etiquetas

Contexto

S-3 Find Anagram Write a function that accepts two words and checks if they are anagrams. In other words check if they contain the same letters exactly regardless of order. It's better before start comparing the two strings to put both to lower case, in order to avoid case sensitivity problems. You may find helpful the .sort() method of an array to complete this task faster. What does the sort do?
Mostrar menos
Sem etiquetas

Contexto

Replace string method The replace function, when attached to a string can replace a part of a string, with another specified string.  The function is simple. Accepts two arguments. The first contains the string that we want to get rid off, and the second contains the string that is going to replace it. Take a closer look to the example above, we replace the word 'negative' which lies inside the sentence string variable, with the word 'positive'. The replaced string is stored into a new string variable.  In the end, line 5 prints: 'I have something positive to say here'
Mostrar menos
Sem etiquetas

Contexto

S-4 Return abbreviation Create variable that should hold this string: "World will not believe it, when i will become a developer!".  Create a function that accepts this string as an argument and returns it's abbreviated form, that means a collection of all the first letters of each word together. All letters should be in upper case at the end.  So your final form should look like: 'WWNBIWIWBAD'. Find a way to ignore the commas and exclamation marks by replacing them with nothing before you start. Use all the strings' and arrays' methods you have learned.
Mostrar menos