how to add character in string in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To add a character in a string in javascript, just use the + operator it will concat two strings in one string and for short syntax, you can also use the += operator. let’s take an example of adding two characters in a single string. let name = ""; name += "Infinite"; name += " "; name += "Ability"; console.log(name) // 👇️ Output // Infinite Ability Today, I’m going to show you How do I add a character in a string in javascript, as above mentioned here, I’m going to use the + operator to add a string to another string....

July 22, 2022 · 3 min · Infinitbility

how to remove special characters and space from number in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To remove special characters and space from number in javascript, just use replace() method with /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/g regex then it will return new string without special characters and spaces then convert it number. The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match....

July 13, 2022 · 2 min · Infinitbility

how to remove special characters and space from string in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To remove special characters and space in javascript, just use replace() method with /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/g regex then it will return new string without special characters and spaces. The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match....

July 13, 2022 · 2 min · Infinitbility

how to convert string to key value pair in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To convert string to key value pair in javascript, use the split(":") and Object.fromEntries() method. the split(":") method help you to convert string to array and Object.fromEntries() method will create array to object. The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call....

June 26, 2022 · 2 min · Infinitbility

how to convert string to number in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To convert string to number in javascript, use + unary plus oprator it’s one of the fastest way to convert string to int. let’s take a example The unary plus operator (+) precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn’t already. In the following example, we can able to convert string to number, float or any negative number using + unary plus oprator....

June 26, 2022 · 2 min · Infinitbility

how to convert string to object key in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To convert string to object key in javascript, use the basic syntax of assign value in object using dynamic keys for example obj["your_key"] = "value". In the following example, we will take example string and convert it on object key. let obj = {id: 1, name: "infinitbility"}; let str = "domain"; obj[str] = "infinitbility.com"; console.log(obj) // {id: 1, name: 'infinitbility', domain: 'infinitbility.com'} Today, I’m going to show you How do i convert string to object key in javascript, as above mentioned here, I’m going to use some basic syntax which can help to assign key value pair dynamically....

June 26, 2022 · 1 min · Infinitbility

how to explode string in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To explode string in javascript, use split() method it will explode your string based upon your parameter you have passed in a split() method. let’s take a example The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call....

June 26, 2022 · 3 min · Infinitbility

How to get difference between two dates in weeks in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get weeks between two dates, Subtract the date to get the difference in nanoseconds. Devied your output time with / 1000 * 3600 * 24 * 7 It will return your difference in dates in a number of weeks. Today, I’m going to show How do I get weeks between two dates in javascript, here I will use the javascript getTime() method and the above-mentioned conditions to get weeks between the start and end date time....

June 10, 2022 · 2 min · Infinitbility

How to get months between two dates in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get months between two dates, Use the getMonth() method to get the months of both dates, and subtract them to get the difference of months Use the getFullYear() method to get the years of both dates, and subtract them to get the difference of years Multiply the year difference by 12 and return the sum. It will return your difference of dates in months....

June 9, 2022 · 2 min · Infinitbility

how to get year difference between two dates in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get years between two dates, Extract both dates and years using the getFullYear() method. subtract them to get a number of years between dates. It will return your difference in dates in a number of years. The getFullYear() method returns the year of the specified date according to local time. Today, I’m going to show How do I get years between two dates in javascript, here I will use the javascript getFullYear() method and the above-mentioned conditions to get years between the start and end date time....

June 9, 2022 · 2 min · Infinitbility

How to get days between two dates in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get days between two dates, Get both dates as a time using the getTime() method. subtract them which you get using the getTime() method. Devied your output time with / 1000 * 3600 * 24 It will return your difference in dates in a number of days. The getTime() method returns the number of milliseconds since the ECMAScript epoch. You can use this method to help assign a date and time to another Date object....

June 8, 2022 · 2 min · Infinitbility

How to get hours between two dates in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get hours between two dates, Get both dates as a time using the getTime() method. subtract them which you get using the getTime() method. Devied your output time with / 36e5 ( 36e5 is the scientific notation for 60601000 ) It will return your difference of dates in number of hours. The getTime() method returns the number of milliseconds since the ECMAScript epoch....

June 8, 2022 · 2 min · Infinitbility

How to get minutes between two dates in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get minutes between two dates, Get both dates as a time using the getTime() method. subtract them which you get using the getTime() method. Devied your output time with / (1000 * 60) % 60 It will return your difference in dates in a minutes. The getTime() method returns the number of milliseconds since the ECMAScript epoch. You can use this method to help assign a date and time to another Date object....

June 7, 2022 · 2 min · Infinitbility

How to check if a string is alphanumeric in JavaScript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check string is alphanumeric, use this regex /^[a-z0-9]+$/i if it gets true means the string contains only alphabets and numbers. Today, I’m going to show How do I check if a string is alphanumeric in javascript, here I will use the javascript test() method and regex as mentioned above to validate whether the string is alphanumeric or not. Let’s start the today’s tutorial How do you check if a string is alphanumeric in javascript?...

June 6, 2022 · 1 min · Infinitbility

How to check if a number is divisible by another number in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check if a number is divisible by another number, use the remainder ( % ) operator if get 0 means the number is divisible else not. Note: Here, another number is any number like 3, 4, 5, 6, 7, 8, etc. Today, I’m going to show How do I check if a number is divisible by another number in javascript, here I will use the modulo ( % ) operator and if....

June 5, 2022 · 2 min · Infinitbility

How to check if a number is between two values in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check if a number is between two values, Apply greater then and less than both conditions with and ( && ) operator. if get true means a number in a range. Note: Here we are using && operator to reduce the number of codes, there have a lot of ways to do that Today, I’m going to show How do I check if a number is between two values in javascript, here I will write some conditions and an if....

June 4, 2022 · 2 min · Infinitbility

How to check if number is prime in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check number is a prime number, looping through 2 to your given number-1 and check is any divisible number or not, if have means it’s not a prime number. Note: 1 is considered neither prime nor composite. Today, I’m going to show How do I check if the number is a prime number or not in Javascript, here I will create a custom function isPrimeNumber() where I will check if there have any divisible number based on this it will return a boolean value....

June 2, 2022 · 2 min · Infinitbility

How to check if a character is a letter or number in JavaScript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check character is a letter or number, JavaScript provides the isNaN() method just pass your character as a parameter it will check character is NaN ( Not a number ) when it returns false means the character is a number else validate the character with regex code /^[a-zA-Z]+$/ to check is a letter or not. Today, I’m going to show How do I check if a character is a letter or number in Javascript, here I will use the javascript string isNaN() method, and regex code /^[a-zA-Z]+$/` to check if a character is a letter or number....

June 1, 2022 · 2 min · Infinitbility

How to check if a string is valid url in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ Today, I’m going to show you, how do you check if a string is a valid URL in javascript, here I will use the regex expression to validate URL string. To validate the string URL, I will use the below regex which can handle the below cases. protocol Domain name address IP (v4) address port and path URL query string fragment locator function isValidURL(str) { var pattern = new RegExp('^(https?...

June 1, 2022 · 2 min · Infinitbility

How to check if number is integer or float in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To check number is an integer or float, JavaScript provides isInteger() method just pass your number as a parameter and it will return true if the number is an integer or else false. Today, I’m going to show How do I check if the number is an integer or float in Javascript, here I will use the javascript string isInteger() method, to check if a number is an integer or float....

June 1, 2022 · 2 min · Infinitbility