Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create half of the string in uppercase and the other half in lowercase?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

To convert half of a string to uppercase and the other half to lowercase, we can use JavaScript's built-in string methods like toUpperCase(), toLowerCase(), and substr() (or substring()). This tutorial demonstrates two effective approaches to achieve this transformation. Using for-loop with toUpperCase() and toLowerCase() This approach uses loops to iterate through the string and convert each character individually based on its position. Syntax for (let i = 0; i < length / 2; i++) { newStr += string[i].toUpperCase(); } for (i = length / 2; i < length; i++) { ...

Read More

Use array as sort order in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 206 Views

In JavaScript, you can sort an array of objects based on a custom order defined by another array. This is useful when you need to arrange data according to a specific sequence rather than alphabetical or numerical order. Problem Statement Given a reference array that defines the desired order and an array of objects, we need to sort the objects so their property values match the sequence in the reference array. const sort = ["this", "is", "my", "custom", "order"]; const myObjects = [ {"id":1, "content":"is"}, {"id":2, "content":"my"}, ...

Read More

Check if items in an array are consecutive but WITHOUT SORTING in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 984 Views

In JavaScript, checking if array items are consecutive without sorting requires verifying that elements form an unbroken sequence. We can solve this using mathematical properties and built-in array methods. What are Consecutive Items in an Array? Consecutive elements form an unbroken sequence where each number differs by exactly 1 from the next. For example, [1, 2, 3, 4, 5] contains consecutive items in ascending order, while [5, 4, 3, 2, 1] is consecutive in descending order. Example Input/Output Input: [11, 12, 13] Output: true Input: [21, 11, 10] Output: false Method 1: ...

Read More

Checking digit sum of smallest number in the array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 277 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should first pick the smallest number from the array and then calculate the sum of all the digits of the number. If the digit sum of that number is even, we should return true, false otherwise. Problem Example If the input array is: const arr = [12, 657, 23, 56, 34, 678, 42]; Then the output should be: const output = false; Because the smallest ...

Read More

Finding alphabet from ASCII value without using library functions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 554 Views

Problem We are required to write a JavaScript function that takes in a number representing an ASCII value. Our function should return the corresponding alphabet character for that ASCII value (if it exists), or -1 otherwise. The condition here is that we cannot use any built-in function like String.fromCharCode() that directly converts ASCII values to characters. Understanding ASCII Values ASCII values for alphabetic characters follow these ranges: Uppercase letters: A-Z have ASCII values 65-90 Lowercase letters: a-z have ASCII values 97-122 Example Following is the code: const num = ...

Read More

crypto.createCipheriv() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 5K+ Views

The crypto.createCipheriv() method creates and returns a cipher object using the specified algorithm, key, and initialization vector (IV). This method is essential for encrypting data in Node.js applications. Syntax crypto.createCipheriv(algorithm, key, iv, options) Parameters The parameters are described below: algorithm – The encryption algorithm to use (e.g., 'aes-256-cbc', 'aes-192-cbc') key – The raw key used by the algorithm. Can be string, ...

Read More

Write a program to display "Hello World" in react native?

Shilpa S
Shilpa S
Updated on 15-Mar-2026 1K+ Views

Once React Native is installed on your system, you get a default code in App.js. This tutorial shows how to modify it to display "Hello World" on your mobile screen. Default App.js Structure When you create a new React Native project, the default App.js contains the following structure: import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; export default class App extends React.Component { render() { return ( ...

Read More

JavaScript: How to Create an Object from Key-Value Pairs

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 3K+ Views

In JavaScript, there are several ways to create objects from key-value pairs. Whether you have individual keys and values or arrays of data, you can build objects dynamically using different approaches. Using Object Literal Syntax The simplest way is to create an empty object and assign properties directly: Object Using Key-value Pair Welcome to Tutorials Point let object = {}; let firstKey ...

Read More

How to Flatten JavaScript objects into a single-depth Object?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 3K+ Views

In JavaScript, flattening an object means converting a nested object structure into a single-depth object where all nested properties are brought to the top level with flattened key names. What is Object Flattening? Object flattening transforms a multi-level nested object into a flat structure. For example, an object like {a: 1, b: {c: 2, d: 3}} becomes {a: 1, "b.c": 2, "b.d": 3} or {a: 1, c: 2, d: 3} depending on the flattening strategy. Method 1: Simple Flattening (Merging Properties) This approach merges nested properties directly into the parent object: ...

Read More

Target a Window Using JavaScript or HTML

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 3K+ Views

In this article we will learn how to use the TARGET attribute to open a website in a new window using HTML and JavaScript. TARGET attribute of HTML A link's opening named frame or window is specified using the Target attribute of the anchor tag. The concluding tag in the HTML content must appear after each commencing tag since the element is paired. Although the href (hypertext reference) element of the anchor tag has several other options, it is required since it contains the URL of the webpage where the link will go when ...

Read More
Showing 15821–15830 of 61,297 articles
Advertisements