Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Concatenate two arrays of objects and remove repeated data from an attribute in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 362 Views

When concatenating two arrays of objects, you often need to remove duplicates based on a specific attribute. This article demonstrates how to merge arrays while handling duplicate entries using map() and find() methods. The Challenge Consider two arrays of product objects where some products appear in both arrays with different properties. We want to concatenate them but prioritize data from the second array when duplicates exist. Example: Merging Product Arrays Let's merge two product arrays and remove duplicates based on productId: var details1 = [ { ...

Read More

How to define a JavaScript function using Function() Constructor?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 282 Views

The Function() constructor expects any number of string arguments. The last argument is the body of the function - it can contain arbitrary JavaScript statements, separated from each other by semicolons. Syntax new Function([arg1[, arg2[, ...argN]], ] functionBody) Parameters arg1, arg2, ...argN: Names to be used by the function as formal argument names (optional). functionBody: A string containing the JavaScript statements comprising the function definition. Example: Basic Function Creation var func = new Function("x", "y", "return ...

Read More

How to return a random number between 1 and 200 with JavaScript?

Manikanth Mani
Manikanth Mani
Updated on 15-Mar-2026 2K+ Views

To return a random number between 1 and 200, use JavaScript's Math.random() and Math.floor() methods. How It Works Math.random() generates a decimal between 0 (inclusive) and 1 (exclusive). To get integers from 1 to 200: Multiply by 200 to get 0 to 199.999... Use Math.floor() to round down to 0-199 Add 1 to shift the range to 1-200 Example You can try to run the following code to return a random number in JavaScript. ...

Read More

How to set the page-break behavior before an element with JavaScript?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 666 Views

Use the pageBreakBefore property in JavaScript to set the page-break behavior before an element. Use the always property to insert a page break before an element. Note āˆ’ The changes would be visible while printing or viewing the print preview. Syntax element.style.pageBreakBefore = "value"; Property Values Value Description auto Default - automatic page break ...

Read More

Use HTML with jQuery to make a form

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 2K+ Views

To create forms with HTML and jQuery, you can either write static HTML forms or dynamically generate them using jQuery's DOM manipulation methods. Creating a Static HTML Form The basic approach uses standard HTML form elements: Student Details: Student Name: ...

Read More

How to invert an object in JavaScript?

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

Inverting an object in JavaScript means swapping its keys and values, so that {name: "John", age: 25} becomes {"John": "name", "25": "age"}. This is useful for creating lookup tables or reverse mappings. There are several ways to invert objects in JavaScript, from using libraries like Underscore.js to native JavaScript methods. Using Underscore.js _.invert() The _.invert() function from Underscore.js provides a simple way to swap object keys and values. Syntax _.invert(object) Parameters: object āˆ’ The object to invert Return Value: A new object with keys and values ...

Read More

Block Scoping in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 401 Views

Block scope is an area between two curly braces { } which can be between loops, if conditions, or switch statements. The let and const keywords introduced in ES2015 allow us to create block-scoped variables that can only be accessed within that specific block. Understanding Block Scope Variables declared with let and const have block scope, meaning they exist only within the nearest enclosing block. This is different from var, which has function scope. Example: Block Scope with let Block Scoping Example ...

Read More

Setting object members in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 190 Views

In JavaScript, you can set object members (properties and methods) in several ways. This allows you to dynamically add or modify object properties after creation. Syntax // Dot notation object.propertyName = value; // Bracket notation object["propertyName"] = value; // Setting methods object.methodName = function() { // method body }; Example: Setting Object Properties Setting Object Members ...

Read More

Sorting objects according to days name JavaScript

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

Let's say, we have an array of objects that contains data about the humidity over the seven days of a week. The data, however, sits randomly in the array right now. We are supposed to sort the array of objects according to the days like data for Monday comes first, then Tuesday, Wednesday and lastly Sunday. Sample Data Following is our array: const weather = [{ day: 'Wednesday', humidity: 60 }, { day: 'Saturday', humidity: 50 }, { ...

Read More

Is there any more efficient way to code this "2 Sum" Questions JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 361 Views

Our job is to write a function that solves the two-sum problem in at most linear time. Two Sum Problem Given an array of integers, we have to find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers that add up to the target, and if no two elements add up to the target, our function should return an empty array. Brute Force Approach - O(n²) The naive approach uses nested loops to check every pair of elements: const bruteForceTwoSum ...

Read More
Showing 17721–17730 of 61,298 articles
Advertisements