Programming Articles - Page 469 of 3363

Golang Program to Convert String to Object

Akhil Sharma
Updated on 16-Feb-2023 18:04:45

3K+ Views

In Golang program, a string is a data type that contains literals and characters whereas an object is a data type created from classes by keeping similar types of properties together. In this article, we will look at two methods by which we can convert a string to an object in go programming language. Syntax func Split(str, sep string) []string Split() function is used to split a string through a provided separator. This function is present in strings package and it accepts the string to split as an argument along with a separator. The function then returns the final ... Read More

How to calculate local time in Node.js?

AmitDiwan
Updated on 16-Feb-2023 15:20:25

6K+ Views

In this article, you will understand how to calculate local time in Node.js. The Date object works with dates and times. Date objects are created with new Date(). JavaScript will use the browser's time zone and display a date as a full text string. Node.js is an open-source and cross-platform JavaScript runtime environment.As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. Example 1 In this example, we use the toDateString and toTimeString function const dateTimeObject = new Date(); console.log("A date-time object is created") console.log(`Date: ${dateTimeObject.toDateString()}`); console.log(`Time: ${dateTimeObject.toTimeString()}`); Output A date-time object is created ... Read More

How optional chaining works in TypeScript?

AmitDiwan
Updated on 16-Feb-2023 15:08:00

437 Views

In this article, you will understand how optional chaining works in TypeScript. Optional chaining operator (?.) accesses an object’s property. If the objects property is null or not defined, it returns ‘undefined’. Let us first understand what TypeScript is. Strongly typed programming language TypeScript, which is based on JavaScript, gives you better tools at any scale. Code written in TypeScript can be converted to execute in any JavaScript-compatible environment. JavaScript is understood by TypeScript, and type inference is used to provide excellent tooling without the need for additional code. Example 1 In this example, we use the optional chaining operator ... Read More

How to communicate JSON data between C++ and Node.js ?

Shubham Vora
Updated on 16-Feb-2023 15:51:20

2K+ Views

C++ is a powerful, high-performance language widely used for system-level programming and applications. At the same time, Node.js is an open-source, cross-platform JavaScript runtime environment commonly used for web applications. By understanding the various methods for communicating JSON data between C++ and Node.js, developers can choose the best approach to their specific needs. In this tutorial, we will explore the various ways to communicate JSON data between a C++ application and a Node.js server. Three common approaches: using a RESTful API, using a message queue, and using a WebSocket Users can follow the steps below to communicate JSON data between ... Read More

Get requests using AJAX by making a Custom HTTP library

Shubham Vora
Updated on 16-Feb-2023 15:35:28

276 Views

We will learn to make a get request using the AJAX by making the custom HTTP library. Let’s learn about the Get request and AJAX before we start with the tutorial. The Get request is used to get or fetch data from the API (Application programming interface). The AJAX stands for Asynchronous JavaScript and XML. The AJAX allows us to load or update new data without reloading the webpage. For example, if you have ever worked with ReactJs, it updates the data without reloading the webpage. If we reload the webpage whenever data updates, it can give a bad user ... Read More

Golang program to replace a character at a specific index

Akhil Sharma
Updated on 13-Feb-2023 15:46:44

2K+ Views

In this tutorial, we will inculcate how to replace a character at a specific index using few examples. The output will be printed on the console using fmt.Println() function. Let’s dive deep into the examples and see how it’s done. Method 1: Using Replace Function In this method, we will learn how to replace a character at a specific index using replace function. The output is printed on console using fmt.Println() function. Let’s understand this through the code. Syntax func Replace(str, oldstr, newstr string, m int) string This function is used to return the copy of the string which ... Read More

Golang Program to remove all 'nil' elements from the array

Akhil Sharma
Updated on 13-Feb-2023 15:44:10

2K+ Views

This tutorial is all about how to remove all nil elements from the array. Basically, sometimes there are empty strings present in the array which we want to remove. Here in this tutorial, we will have a look how to remove those strings with the use of very simple methods. Method 1: Using helper Function Approach In this method, we will see how to remove null elements using helper function approach. The array will be taken as a parameter in the function and the output will be printed on console using print statement of Golang. Syntax func append(slice, element_1, element_2…, ... Read More

Golang program to iterate over a Slice

Akhil Sharma
Updated on 13-Feb-2023 15:38:02

3K+ Views

In this tutorial, we will iterate over a slice using different set of examples. A slice is a dynamic sequence which stores element of similar type. The iterated list will be printed on the console using fmt.Println() function. Method 1:Using for Loop with Index In this method, we will iterate over a slice using for loop where both the index and its element will be printed on the console screen. Let’s have a look how to execute this example. Algorithm Step 1 − Create a package main and import fmt package in the program. Step 1 − Create a package ... Read More

Golang program to fill an array with a specific element

Akhil Sharma
Updated on 13-Feb-2023 15:35:44

3K+ Views

In this tutorial, we will learn how to fill an array with a specific element. We will explore few examples to know more about this program. The output will be printed on console using fmt.Println() function. Let’s have a look and understand the program. We have used the following make() function in the examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. Method 1: Using for Loop and Make Function in Main Function ... Read More

Golang program to find the prime numbers from the array

Akhil Sharma
Updated on 13-Feb-2023 15:31:52

530 Views

In this tutorial, we will showcase how to find the prime numbers from the array using different examples. Prime numbers are those numbers which are either divisible by 1 or by themselves they have no factor other than this. Now we will present you few illustrations to help you get clear with the logic behind this program. Method 1: Finding Prime Number in the main Function In this particular method, we will print the prime numbers with the help of nested for loops. We will half the array elements in every inner iteration and check whether they are divisible or ... Read More

Advertisements