Articles on Trending Technologies

Technical articles with clear explanations and examples

Extract properties from an object in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

We have to write a JavaScript function, say extract() that extracts properties from an object to another object and then deletes them from the original object. For example − If obj1 and obj2 are two objects, then obj1 = {color:"red", age:"23", name:"cindy"} obj2 = extract(obj1, ["color", "name"]) After passing through the extract function, they should become like − obj1 = { age:23 } obj2 = {color:"red", name:"cindy"} Therefore, let's write the code for this function − Syntax const extract = (obj, ...keys) => { ...

Read More

Search and update array based on key JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 244 Views

In JavaScript, you often need to merge data from two arrays based on a common property. This is useful when you have reference data in one array and need to enrich objects in another array. Consider these two arrays: let arr1 = [ {"LEVEL":4, "POSITION":"RGM"}, {"LEVEL":5, "POSITION":"GM"}, {"LEVEL":5, "POSITION":"GMH"} ]; let arr2 = [ {"EMAIL":"test1@stc.com", "POSITION":"GM"}, {"EMAIL":"test2@stc.com", "POSITION":"GMH"}, {"EMAIL":"test3@stc.com", "POSITION":"RGM"}, {"EMAIL":"test3@CSR.COM.AU", "POSITION":"GM"} ]; console.log("Original arr2:", arr2); ...

Read More

Make HTML text input field grow as I type in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 559 Views

Making HTML text input fields grow automatically as users type enhances user experience by eliminating the need to scroll within small input boxes. There are several approaches to achieve this dynamic resizing behavior. Using Contenteditable Span The simplest approach uses a element with contenteditable="true", which automatically expands as content is added: Growing Input Field .growing-input { ...

Read More

Move string capital letters to front maintaining the relative order - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 379 Views

We need to write a JavaScript function that takes a string with uppercase and lowercase letters and returns a new string with all uppercase letters moved to the front while maintaining their relative order. For example, if the input string is: const str = 'heLLO woRlD'; Then the output should be: const output = 'LLORDhe wol'; Algorithm Explanation The approach uses an array and a tracking index. We iterate through each character, and if it's uppercase, we insert it at the current capital position and increment the index. Lowercase characters ...

Read More

How can I remove the decimal part of JavaScript number?

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

In this tutorial, we will learn to remove the decimal part of the number in JavaScript. While working with JavaScript, many times, developers need to play with the numbers stored in the database and needs to convert float and double numbers into the pure decimal or integer number. In this situation, developers can have multiple methods to truncate the decimal part of the number. We will see different approaches to overcome the above problem. Using the Math.trunc() method Using the Bitwise operators Using the Math.ceil() ...

Read More

How to show the full URL of a document with JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 2K+ Views

We use the URL property of the document object to show the full URL of a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. URL stands for Uniform Resource Locator. It contains the address of a resource on the internet. A typical URL looks something like this: http://www.example.com/index.html The Document Object Model of JavaScript acts as a layer of abstraction on the HTML page, creating ...

Read More

How to set the style of the left border with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 387 Views

In this tutorial, we shall learn how to set the style of the left border with JavaScript. To set the style of the left border in JavaScript, use the borderLeftStyle property. Set the style under this property that you want for the border i.e. solid, dashed, etc. Using the borderLeftStyle Property With this property, we can set or return the style of the left border of an element. Syntax object.style.borderLeftStyle = style; This syntax allows the required border style to be set to the element's style. Parameters ...

Read More

Difference between Session Storage and Local Storage in HTML5

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 886 Views

HTML5 provides two web storage mechanisms: Session Storage and Local Storage. Both allow web applications to store data locally in the user's browser, but they differ in scope and persistence. Session Storage Session Storage is designed for scenarios where the user is carrying out a single transaction but could be carrying out multiple transactions in different windows at the same time. Data stored in Session Storage is only available for the duration of the page session. // Store data in Session Storage sessionStorage.setItem("username", "john_doe"); sessionStorage.setItem("theme", "dark"); // Retrieve data from Session Storage console.log("Username:", sessionStorage.getItem("username")); ...

Read More

Set dashed line for border with CSS

George John
George John
Updated on 15-Mar-2026 810 Views

To set the dashed line for the border, use the border-style property with the value dashed. This creates evenly-spaced dashes around the element's border. Syntax border-style: dashed; /* or combine with width and color */ border: width style color; Example This is a dashed border. Different Dashed Border Styles ...

Read More

How to get the size of a json object in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 10K+ Views

In this article, we will learn about various methods to get the size of a JSON object in JavaScript. Getting the size of a JSON object in JavaScript is the same as counting the total number of keys in an object. We can accomplish this using several different approaches. Using Object.keys() (Recommended) The Object.keys() method returns an array of the given object's enumerable property names. To get the size, we simply check the length of this array. Syntax Object.keys(objectName).length Example Size of JSON Object ...

Read More
Showing 17141–17150 of 61,297 articles
Advertisements