About Lesson
JavaScript functions for string and array manipulation
JavaScript has a variety of built-in functions and methods that make it easy to manipulate strings and arrays. Here are some common ones:
- String functions:
- CharAt(index): returns the character at the specified index of a string
- Concat(string1, string2, …, stringX): combines two or more strings into a single string
- IndexOf(searchValue): returns the index of the first occurrence of the specified search value in a string
- Replace(searchValue, replaceValue): replaces the first occurrence of a specified value in a string with another specified value
- Slice(startIndex, endIndex): extracts a section of a string and returns it as a new string
- Split(separator): splits a string into an array of substrings based on a specified separator
- ToLowerCase(): converts a string to lowercase
- ToUpperCase(): converts a string to uppercase
- Trim(): removes whitespace from the beginning and end of a string
- Array functions:
- concat(array1, array2, …, arrayX): combines two or more arrays into a single array
- filter(callback): creates a new array with all elements that pass the test implemented by the provided callback function
- indexOf(searchElement): returns the index of the first occurrence of a specified element in an array
- join(separator): joins all elements of an array into a string, using a specified separator
- pop(): removes the last element from an array and returns it
- push(element1, element2, …, elementX): adds one or more elements to the end of an array and returns the new length of the array
- reverse(): reverses the order of the elements in an array
- shift(): removes the first element from an array and returns it
- slice(startIndex, endIndex): returns a section of an array as a new array
- sort(): sorts the elements of an array in place
- splice(startIndex, deleteCount, element1, element2, …, elementX): adds and/or removes elements from an array
By using these functions and methods, you can easily manipulate strings and arrays in your JavaScript code.