At first, I say about String. What is String? It’s an object which is used to represent and manipulate a sequence of characters. Some popular String methods are charAt, concat, includes, endsWith, indexOf, lastIndexOf, replace, slice, split, startsWith, substr, toLowercase, toUppercase, trim, trimStart, trimEnd.
I will discuss the first four methods.
charAt(): The charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.
Syntax: chartAt(index). This method returns an empty string.
includes(): This method checks a specific word or number is available on a string or not. Suppose I have a variable named hello. In hello variables I have some string-like, var hello= “I am the king in my kingdom”. If I try to find king from the hello variable then I use the includes() method. The way is var s= hello.includes(“king”). If the king string is not in hello variable then it returns false otherwise it returns true.
endsWith(): This is similar like includes(). includes searching the string is available in the variable or not. Where endsWith() search the last string of a variable, if it’s true it returns true value otherwise return a false value.
I will discuss isNan, Abs, floor in this article.
isNan(): The isNaN() function defines the value we provide is number or not. isNaN means is Not a Number.
isNaN(‘Hello’) = true, isNaN(123) = false
In the first example, the “hello” string is a collection of a word, so it’s not a number. That’s why it’s true. In the second example, the “123” is a collection of numbers, that’s why the value is false.
abs(): The abs() method returns the absolute value of a number.
Absolute means positive value. Suppose I have a value which is -5.25. If I want to make it positive then I use the abs() function.
floor(): The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.
Suppose I have a value that is 3.4. If I want to make the float number into an integer then I use the floor function. Here I catch 3.4, if I use the floor function here, then it returns 3.
I will discuss forEach, Map, Filter method here.
forEach(): The forEach() method calls a function once for each element in an array, in order. If I need this type of work like I have an array and I need to go to every element of an array for a specific result then I use the forEach() method. It has no return value.
Map(): If I need a value after executing an array then I must use the Map() method. If I use the Map() method in multiple lines then I must use the return term If I want a value for return.
filter(): If I need any logical value from an array then I use the filter method. Suppose I have an array, var ages = [32,22,55,44,10]. Now I need the values which are greater than 20, that’s the time I use the filter() method. And it will execute like this, ages.filter(age => age > 20); , the expected output is = 22,32,44,55. So, use the filter method I find out what I need.