Javascript Articles

Page 264 of 534

How to set a String as a key for an object - JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 6K+ Views

In JavaScript, it is common to use a string as a key for an object, especially when you want to dynamically create or change the properties of the object. Objects are fundamental data structures that allow you to store collections of data in key-value pairs. You can use strings as keys directly. It is a simple and straightforward method. This article will guide you how to use a string as a key for an object. Using Computed Property Names (ES6) The most modern approach is using computed property names with bracket notation inside the object literal. This allows ...

Read More

How to sort an object in ascending order by the value of a key in JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 923 Views

Sorting an object in ascending order by the value of a key is a common task in JavaScript. Objects are data structures, which are a collection of key-value pairs. Since objects in JavaScript are unordered collections, sorting them directly is not possible. This article will guide you on how to sort an object in ascending order by the value of a key in JavaScript. Understanding the Concept Suppose we have the following object: const obj = { "sub1": 56, "sub2": 67, "sub3": 98, "sub4": ...

Read More

JavaScript - Create an alert on clicking an HTML button

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 5K+ Views

In this article, we will learn to create an alert by clicking an HTML button in JavaScript. JavaScript is extensively utilized to increase user interactions on web pages. One of the widespread usage scenarios is to display an alert on a button click. What is an Alert in JavaScript? An alert is a built-in JavaScript function that displays a small pop-up or a dialogue box window containing a message. The syntax for using an alert is: alert("Your message here"); This function pauses the execution of the script until the user dismisses the alert ...

Read More

Removing all non-alphabetic characters from a string in JavaScript

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

Non-alphabetic characters are any characters that are not part of the alphabet, and the strings are a data type that represents a sequence of characters or text. Working with strings is a basic task in JavaScript, and one common task is removing all non-alphabetic characters from a string. In this article, we will understand how to remove all non-alphabetic characters from a string. Understanding the Problem Suppose we have a string saying "he@656llo wor?ld". We want to remove all digits, punctuation, whitespace, and special characters from the given string. For example: Input string we have: "he@656llo wor?ld" ...

Read More

Changing the npm start-script of Node.js

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

The start-script of a Node.js application consists of all the commands that will be used to perform specific tasks. When starting or initializing a Node.js project, there are predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project. Script commands are widely used for making different startup scripts of programs in both Node and React. npm start is used for executing a startup script without typing its execution command. Package.json File Structure The start script needs to be added in the package.json file. ...

Read More

send(), sendStatus() and json() method in Node.js

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

In Express.js, the send(), sendStatus(), and json() methods are essential for sending responses to clients. The send() method sends data in string format, json() sends data in JSON format with proper headers, and sendStatus() sends HTTP status codes with default status messages. Prerequisites Node.js installed Basic understanding of Express.js Installation Install the Express module using npm: npm install express Understanding sendStatus() Method The sendStatus() method sends an HTTP status code along with its default message. Common status codes include 200 (OK), 404 (Not Found), 201 (Created), ...

Read More

Achieving maximum possible pair sum in JavaScript

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 296 Views

The maximum possible pair sum is a traditional problem in Data Structures and Algorithms (DSA). In this problem, we calculate the sum of two elements (i.e., pairs) in an array such that the resulting sum is the maximum among all possible pair sums. For example, we have an array [1, 2, 3, 4]. The sum of the pair (3, 4) is 7, which is the maximum among all pair sums in the given array. Problem Statement We have given an array named nums[], and our task is to write a JavaScript program to achieve the maximum possible ...

Read More

Add number strings without using conversion library methods in JavaScript

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 313 Views

We are required to write a JavaScript program that adds two numbers represented as strings, without using any conversion library or built-in methods. For example, If the input number strings are '11' and '23', the output should be '34'. In JavaScript, a number is considered a string-represented number when the number is enclosed in single quotes ('number') or double quotes ("number"). For example: '123' or "456". If you use the typeof operator on such values, it will return the type as 'string'. Here are a few input and output scenarios that provide a better understanding of the given ...

Read More

How to print a number with commas as thousands of separators in JavaScript?

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

In this tutorial, we will look at a few ways to print a number with commas as thousands of separators in JavaScript and compare them to understand which one is suitable in a given context. Why do we do number formatting? In English, commas are used to separate numbers bigger than 999. Dot is the thousands separator in Germany. Sweden uses space. The separator is added after every three digits from the right. Let's briefly introduce the methods. Using the toLocaleString() Method Here, the built-in locale string method localizes the number format based on the country. ...

Read More

How can I store JavaScript objects in cookies?

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

This tutorial will teach us to store JavaScript objects into the cookies. The cookies are the information of website visitors stored in text files. There is a particular mechanism to store the cookies of users' browsers. When new visitors visit the website, the server generates the text and sends it to the user. After that, when users allow access to the web page to retrieve the cookies, the server stores all user information in the text files. Cookies store the user's search history or other information for a better experience. For example, Google stores the user's search history to ...

Read More
Showing 2631–2640 of 5,340 articles
« Prev 1 262 263 264 265 266 534 Next »
Advertisements