How to Check if a String Contains a Substring in TypeScript?

Check if a String Contains a Substring in TypeScript

Recently, I got a requirement to check if a string contains a substring in TypeScript. In this tutorial, I will explain how to check if a string contains a substring in TypeScript using different Check if a String Contains a Substring in TypeScript TypeScript, being a superset of JavaScript, inherits all string manipulation methods from … Read more >>

How to Convert a String to a Date in TypeScript

TypeScript string to date: Command Prompt output showing a date-only string parsed as the previous day in New York

To convert a string to a date in TypeScript, pass an ISO 8601 string to new Date(), such as new Date(“2026-10-08T14:30:00”). Then check the result, because a bad string gives an Invalid Date instead of an error, and a date-only string is read as UTC: Time zones change the answers here, so every run used … Read more >>

How to Convert Date to String Format DD/MM/YYYY in TypeScript?

Convert a date to a DD/MM/YYYY string in TypeScript: Command Prompt output of tsc and node printing 14/11/2025

I recently got a particular requirement from one of the clients. The client wanted to convert a date to a string format DD/MM/YYYY in TypeScript. In this tutorial, I will explain how to convert a date to a string in the DD/MM/YYYY format using TypeScript with some examples. Different regions use different date formats. For … Read more >>

Generate Random Strings in TypeScript

Recently, I was required to create some random strings in TypeScript. There are various methods to do so. In this tutorial, I will explain multiple approaches to generating random strings in TypeScript with examples. You might generate random strings to create unique identifiers, temporary passwords, etc. Generate Random Strings in TypeScript Now, let me show … Read more >>

How to Add Elements to an Empty List in Python

Python add elements to an empty list: Command Prompt output of append() filling a shopping cart list

If you need to add elements to an empty list in Python, call cart.append(item) to add one element, or cart.extend([…]) to add several at once. Both change the list in place. Where people get stuck is the small stuff: append() with a list nests it, and assigning the result of append() gives you None. In … Read more >>

How to Remove Duplicates from a List in Python

Python remove duplicates from a list: Command Prompt output of dict.fromkeys keeping the first Austin order

A lot of answers on how to remove duplicates from a list in Python still loop with if x not in result before every append. It works, but it rescans the result each time. The better answer is list(dict.fromkeys(items)). It’s one line, it keeps the original order, and it makes a single pass over the … Read more >>

How to Format Dates in TypeScript (5 Methods)

TypeScript format date: Command Prompt output of toLocaleDateString formats for an order date

Imagine a shipping-label screen for a US warehouse. The label needs “Saturday, October 10, 2026”, the database wants a sortable string, and the file name wants 2026-10-10. That’s three ways to format a date in TypeScript, from one Date. To format a date, or convert a date to a string, use toLocaleDateString(“en-US”, options) for display … Read more >>

How to Remove All Instances of an Element from a List in Python

Python remove all instances of an element from a list: Command Prompt output of a list comprehension removing Austin from seven orders

If you’ve called remove() on a Python list and found that duplicates are still sitting there, you’re not doing anything wrong. To remove all instances of an element from a list, use a comprehension: [x for x in items if x != value]. The reason is simple: list.remove() deletes only the first match and then … Read more >>

How to Remove the Last Element from a List in Python

Remove the last element from a list in Python: Command Prompt output of list.pop() undoing actions

To remove the last element from a list in Python, call my_list.pop(). It deletes the final item and hands it back to you. If you don’t need the value, del my_list[-1] does the same job: The outputs below came straight from Python 3.12.5, using a shopping cart and an undo history as examples. We’ll go … Read more >>

How to Randomly Select from a List in Python

Randomly select from a list in Python: Command Prompt output of random.choice picking cities

To randomly select from a list in Python, use random.choice(my_list) for one item. For several items without repeats, use random.sample(my_list, k); with repeats or weights, use random.choices(): Each pick below is real output from Python 3.12.5 with NumPy 2.5.3. Most examples use a seed, so you can reproduce them exactly. You’ll see choice and seeding, … Read more >>