DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

JavaScript String Guides

JavaScript strings are not always so straightforward, especially how they interpolate and can be interpreted as numbers. Let's get to the bottom of all the functionality in these guides.

This is a collection of top and trending guides written by the community on subjects related to JavaScript String concepts. For all things JavaScript, check out the JavaScript tag! Please contribute more posts like this to help your fellow developer in need.

6 formas de convertir un String en Array con Javascript

El spread operator es de la nueva version de ES6 y funciona ya en todos los navegadores. Este nos ayuda extraer y propagar cada letra o character del string utilizado. Nosotros solo tenemos que envolver la propagaciΓ³n de esa cadena dentro de nuestras llaves cuadradas para poder crear un nuevo array a partir del string dado.


User Agent string difference in Puppeteer headless and headful

As mentioned here https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent, User Agent string is a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent.


Using Typescript string enums? Consider string literals!

Can I use string values instead of numbers on TypeScript enums?


How to get Query String Parameters in Javascript - 2019

This series is a quick javascript tricks that you can learn in 2 mins. In this article, How to get Query String Parameters in Javascript - 2019.


How to check if a string contains at least one number using regular expression (regex) in JavaScript?

To check if a string contains at least one number using regex, you can use the \d regular expression character class in JavaScript.


Get Byte size of the string in Javascript

As we all know a byte is one the unit of digital information, and while development taking care of the size of variables, records and files are a much important task. To do that we have various ways but with these functions, it’s very easy to do. byteSize() snippet will take a string as an input and in the output, it’ll return byte size of a given string. Let’s look at the syntax…


The string-matching regex explained step by step

I'm pretty sure that if the Stack Overflow survey asked developers what is their greatest fear, the top 1 spot would be held by regular expressions. And while some simple ones are not-so-complicated to make, there is one in particular that I've been avoiding for over a decade before finally trying to understand it... Matching a string literal!


Convert an array of objects to CSV string in JavaScript

On some occasions at work, we've needed to generate a CSV string on the server-side to send to our front-end app where the user can download a spreadsheet file e.g. report.


Javascript Algorithms #1: Counting the Vowels in a String OfΒ Text

Basically, we want to be able to receive a string of text of any length and return the number of vowels found within the text.


Ways to convert string to date in Javascript

A string date can be of three types and, we will convert each of those to a date object in javascript.

Formats of stringΒ date:


Hooks to persist state in the query string or history.state in React

Good URLs enable users to keep a reference to web applications in a specific state or to share them with other people. While the path of the URL usually defines the page the user is on, eg. a search results page (/search), the query string is often used to encode a custom state of that page, eg. a search query for "shoes" with a set of filters for colors and size (/search?q=shoes&color=blue&color=black&size=44). A user could now bookmark this URL to come back later or share it with a friend or click on one of the products to check it out in detail, and if they want to return to the results page, they could just use the back functionality to go back to the same search results and select another product.


How to Render HTML string in a React component ?

In this tutorial we will see how to render HTML string in a React component.


10 JavaScript string methods you should know

In this post I will summarize 10 javascript string methods you should at least known according to me.


CodeToday: "Convert string to camel case" algorithm, CodeWars

4) On to the for loop which I wrote with the ES6 syntax. Remember that splitString is an array with my string split into comma separated elements. Let's start iterating through every element, using the variable word. I will use the split method on every word, splitString[word], to further break down my string into something that would look like

[ 's', 't', 'e', 'a', 'l', 't', 'h' ]
, for example & I'll store them in an array called splitWords.


Reverse a String - Four JavaScript Solutions

The reverse a string problem is a common algorithm problem. In this article, we will consider four JavaScript solutions to it.


Replacing query-string with Native URLSearchParams

query-string is an awesome package which allows you to parse URL parameters, however, you may not need it anymore.


Solution: Remove All Adjacent Duplicates in String II

Given a string s, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them causing the left and the right side of the deleted substring to concatenate together.


4 different ways to reverse a string with JavaScript

Reversing a string is perhaps one of the most common interview questions one of those which inevitably we, as Software Developers, encounter during our journeys.


Typescript: String Enums, the easy way

This blog was originally published by Navneet Karnani ( navneet@mandraketech.in ) on his blog at: https://blog.mandraketech.in/typescript-string-enums


Two string methods every JavaScript developer should know.

Here's the thing though, while testing the endpoint, I realized that I wasn't successfully querying the db because I was getting the date in this form '"2019-08-02T00:00:00.000Z"'. Meanwhile I needed it in this form: '2019-08-02'. So I needed to separate the time from the date-time string and remove the double quotes from the string.


How to convert a Js string to an array

How to convert a Js string to an array


Three Ways to Find the Longest Word in a String using JavaScript

In this article, I'm going to share with you 3 ways to find the longest word in a string using JavaScript. They are:


JavaScript Challenge 6: Convert string to camel case

In this article we will solve together the Convert string to camel case challenge from CodeWars, you can find it at this link. The difficulty of this challenge is easy.


Three ways of accessing string characters in JavaScript

How do we access characters in a string? Well, in this post we look at three ways that we can use to access a character at a particular index, i, in a string. In a string characters are indexed from left to right. For instance, in a string named str the first character is at index 0, while the last is at index str.length-1


How to append a string to URL?

In this post, I will be able to allow you to skills to feature or update query string parameter to current URL using JavaScript and also, you’ll skills to feature query string to the current URL without reloading page.


Regular Expressions - Grouping and string methods

In the above regexp, We have several "+" operators, as well as a parentheses group. Notice that we have surrounded "ha+" in parentheses, then followed those parentheses by a "+" operator. This means that the string of "ha" can occur any number of times, with any number of "a"s trailing the "h". We can also combine parenthesis with the pipe operator "|", which functions similarly to the Javascript "or" operator. This operator denotes that the choice on either side of the operator will produce a match:


Reverse a String in JavaScript

Reversing a String is indeed one of the most common and needed operations in JavaScript. During the journey of any Software Developer's career, a very important and basic question for interviews is "How to Reverse a String in JavaScript"


How to split string without using JS's inbuilt spit function

How to split the string without using JS's inbuilt split function?


How to check if a string contains emojis in JavaScript?

To check if a string contains emojis in JavaScript, we can use a regex expression to match a range of Unicode specific to emojis.


Derive union of string literal types with lookup types in Typescript

Recently I started playing with unions of string literals as an alternative to enums. I did not experience any issues while using enums. I just prefer the string literals as these, in contrast to enums, do not lead additional code generated during compilation.


Solution: Check If a String Contains All Binary Codes of Size K

Given a binary string s and an integer k.


Template String Types as Discriminants in Typescript 4.5

Typescript 4.5 was just released and one of the features that stood out to me is the Template String Types as Discriminants. In this article, we are going to explore this new feature using rudimentary examples. In my last article, we covered using discriminated unions to write better types that are easy to narrow.


Javascript Date String Parsing

One of my favorite features of PHP is the strtotime function. This function lets you pass in a date string and have a unix timestamp returned


Backspace String Comparisons: Two Ways To Approach a Common Algorithm

Inside the first for loop, we will check if the character we're currently on in the string is "#". If it's not, then we will add that character to the string using .push(). If it is, then we will simply pop off the last element from the sArr array. We can do the same in the second loop with the T input and the tArr.


Converting CSV string to a 2D array of objects in ES6

In this article I will explain how to convert a comma-separated values (CSV) string to a 2D array of object using Javascript.


The difference between String and string in Typescript

TypeScript is a good advancement in the javascript ecosystem.

Today we are going to talk about the difference between the String and string types in Typescript.


JS custom string interpolation

Since ES6, we have been able to use the powerful template literals instead of the clumsy string concatenations.


Sort a String using a Custom Alphabet in Javascript

It took us both a little bit of troubleshooting to get it working live, and we joked that that was the first part of the code challenge; "Can you successfully set up a live code sandbox". Once it was rolling, he told me the first part was to return a string so that it is sorted alphabetically. I asked about case sensitivity and he listed the assumptions: all lowercase and no special characters including spaces. I also asked if it was ok that we test the function using console.logs instead of displaying it to the browser. He agreed as that would remove a layer of abstraction.


Solution: Smallest String With A Given Numeric Value

The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string "abe" is equal to 1 + 2 + 5 = 8.


Solution: Determine if String Halves Are Alike

You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.


Sustainable string enums in Typescript

To add a new option we just add a new string to the options array. That's not bad, but we still have to update the PostStatus type whenever the data schema is adjusted, along with adjusting this component. Is there a way to update the PostStatus type and have that propagate to this dropdown?


Get the domain name from a string containing a URL in JavaScript

First let’s create a string with our URL (http://koneksi-aman.com/proxy/index.php?q=f6W-ymqPk8BQrZiddK-_jWaqx90X58_keaqkp-Cq3OKdr2rYpOG_vaSuop24euawuyPUCKHTVte-u1WW3GXe4KOlvA).


How to uppercase the first letter of a string in JavaScript

JavaScript offers many ways to capitalize a string to make the first character uppercase. Learn the various ways, and also find out which one you should use, using plain JavaScript.


Reversing a String in Place

Today's algorithm of the day is the Reverse String problem:


Happy JavaScript String coding!