25+ JavaScript Methods Explained π€―
- Strings
- Objects
- Numbers
- Arrays
A mega-thread π§΅
π String
A JavaScript string stores a series of characters or a string is a collection of characters. A string can be any text inside double or single quotes.
String Methods π
β
toUpperCase()
The toUpperCase method is used to convert a string to upper case.
β
toLowerCase()
The to Lowercase is used to convert a string to lower case.
β
slice()
This method is used to return the sliced part of a string, it takes one or two arguments that indicate the initial and end of the slice. The arguments can also be negative.
β
substr()
This method is similar to slice, however, the second parameter indicates the length of the part that should be extracted.
β
replace()
The replace method is used to replace a part of a string with another string. This method is case-sensitive.
β
concat()
This method is used to concatenate two or more strings.
β
trim()
This method is used to remove the spaces from both sides of the string.
β
charCodeAt
The charCodeAt returns the unicode of the character at a specified index in a string.
β
charAt()
This method returns the character of a specific index in a string.
β
padStart
This method is used to add padding at the starting of a string.
β
padEnd
It adds padding at the end of the string.
β
length
This method is used to return the length of a string.
π Objects
The Object is the JavaScript data type. It is used to store various keyed collections and each key can have a value.
Object Methods π
β
keys()
This method returns the keys of an object.
β
values()
This method returns the values of an object.
β
create()
This method is used to create a new object from the existing object.
β
freeze()
The Object.freeze() method freezes an object. This method will allow an object to be changed, freezing an object prevents changing, for example, adding new properties to it, removing existing properties from it.
β
assign()
This method is used to copy the properties of one object to another object.
π Numbers
The number is the numeric data type of Javascript that stores normal integer, floating-point values.
Numbers methods π
β
toFixed()
This method writes the number with a specified number of decimals and returns its value as a string.
β
parseFloat()
This method converts the function argument to a string first and returns a floating-point number.
β
Number()
This method is used to convert the value of other data types to numbers.
β
parseInt()
This method converts the function argument to a string first and returns an integer.
π Array
Array is a single variable that store a list of values and each element is specified by a single index.
Array Methods π
β
pop()
The pop() method removes the last element of an array.
β
shift()
The shift() method removes the first element from an array.
β
push()
The push() method adds one or more elements to the end of an array.
β
length
The length returns the number of elements in an array.
That is it :D
If you found this thread useful, consider:
β
Following me @SuhailKakar for more content like this
π Retweeting the first tweet.
Thanks for your support π
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.