javascript
- 05 October
Get Nth Character in String in JavaScript
In this post, we will see how to get Nth Character in String in JavaScript. Using charAt() method To get nth character in String, you can use String’s charAt() method. chatAt() method accepts index as an argument and return the character at the given index. If index is out of bound for string, charAt() method […]
- 05 October
Get Filename from Path in JavaScript
This article explains the various ways to get filename from path in JavaScript. Get Filename From Path in JavaScript Finding a file name from its file path is a simple task. The program needs to find the last delimiter, and get everything that occurs after it. There are multiple ways to get filename from Path […]
- 25 May
Remove Double Quotes from String in JavaScript
In this post, we will see how to remove double quotes from String in JavaScript. Ways to Remove Double Quotes from String in JavaScript There are multiple ways to do it. Let’s go through them. Using replace() To remove double quotes from String in JavaScript: Use replace() method with regular expression /"/g as first parameter […]
- 25 May
Convert Seconds to Hours Minutes Seconds in Javascript
In this post, we will see how to convert seconds to Hours Minutes Seconds in JavaScript. There are multiple ways to do it. Let’s go through them. Using javascript without any external library To convert seconds to Hours Minutes Seconds in javascript: Create new date object with its constructor. Pass seconds to setSeconds() method on […]
- 25 May
Remove First Character from String in JavaScript
In this post, we will see how to remove first character from string in JavaScript. Since Strings are immutable in JavaScript, you can’t do it in-place. All the methods will return new String and you can either assign it to same variable or to new one. Ways to Remove First Character from string in JavaScript […]
- 25 May
[Solved] TypeError: toLowerCase is not a function in JavaScript
TypeError: .toLowerCase is not a function occurs when we call toLowerCase() function on object which is not an string. toLowerCase() function can be only called on string. To resolve this issue, convert value to string using toString() ,method before calling toLowerCase() method. Let’s see with help of simple example [crayon-6768a0b4320a8058562220/] You will get following error […]
- 25 May
Escape Json String Containing Newline Characters in JavaScript
In this post, we will see how to escape JSON string containing newline characters using JavaScript. There is no well known JavaScript library which can escape all special characters in String. Escape JSON string in JavaScript There is no direct way to escape JSON String in JavaScript. You could however chain string's replace() method and […]
- 23 May
Escape Apostrophe in JavaScript
In this article, we will see how to escape Apostrophe in JavaScript. Let’s see what happens if we have singe quote in String and we also use single quotes to declare the string in JavaScript. [crayon-6768a0b4322ad540907487/] Output: unknown: Unexpected token (1:26) Ways to escape Apostrophe in JavaScript There are multiple ways to escape quotes in […]
- 23 May
TypeError: foreach is not a function in JavaScript
TypeError: .foreach is not a function occurs when we call foreach() function on object which is not array, Set or Map. To resolve this issue, you can use Object.keys() rather than directly calling foreach() on object or use Array.from() to convert array like object to array. In other words, call foreach() method only on iterable […]