Front End Technology Articles

Page 215 of 652

Iterate through Object keys and manipulate the key values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 318 Views

When working with arrays of objects in JavaScript, you often need to iterate through object keys and transform their values. This article demonstrates how to extract specific elements from array values within objects. Problem Statement Suppose we have an array of objects where each property contains an array of values: const arr = [ { col1: ["a", "b"], col2: ["c", "d"] }, { ...

Read More

Convert mixed case string to lower case in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 467 Views

In JavaScript, there are multiple ways to convert a mixed-case string to lowercase. The most common approach is using the built-in toLowerCase() method, but you can also implement a custom solution using character codes. Using the Built-in toLowerCase() Method The simplest and most efficient way is to use JavaScript's built-in toLowerCase() method: const str = 'ABcD123'; const output = str.toLowerCase(); console.log(output); abcd123 Custom Implementation Using Character Codes For educational purposes, here's how to implement a custom convertToLower() function that converts uppercase letters (ASCII 65-90) to lowercase by adding 32 to ...

Read More

Checking for straight lines in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 560 Views

We need to write a JavaScript function that takes an array of coordinate pairs and determines if all points form a straight line. Each subarray contains exactly two items representing x and y coordinates. Our function checks whether the coordinates form a straight line by calculating and comparing slopes between points. For example: [[4, 5], [5, 6]] should return true (slope = 1) [[1, 2], [2, 3], [4, 5]] should return true (all have slope = 1) [[1, 1], [2, 2], [3, 4]] should return false (different slopes) The array is guaranteed to contain ...

Read More

Can one string be repeated to form other in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 161 Views

We are required to write a JavaScript function that takes in two strings, str1 and str2, as the first and the second argument. Our function should return the minimum number of times we should repeat string str1 so that string str2 is a substring of it. If it is impossible for str2 to be a substring after repeating it, we should return -1. Problem Example For example, if the input to the function is: const str1 = 'wxyz'; const str2 = 'yzwxyzwx'; The expected output is 3, because by repeating str1 three times ...

Read More

Finding the power of a string from a string with repeated letters in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 600 Views

The power of a string is the maximum length of a non-empty substring that contains only one unique character. We are required to write a JavaScript function that takes in a string and returns its power. For example − const str = "abbcccddddeeeeedcba" Then the output should be 5, because the substring "eeeee" is of length 5 with the character 'e' only. How It Works The algorithm traverses the string and counts consecutive identical characters. It tracks the maximum count found, which represents the power of the string. ...

Read More

Finding day of week from date (day, month, year) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 804 Views

We are required to write a JavaScript function that takes in three arguments, namely: day, month and year. Based on these three inputs, our function should find the day of the week on that date. For example: If the inputs are − day = 15, month = 8, year = 1993 Output Then the output should be − const output = 'Sunday' Using Built-in Date Object (Simple Method) The easiest approach is to use JavaScript's built-in Date object: function getDayOfWeek(day, month, year) { ...

Read More

crypto.createDiffieHellman(primeLength, [generator]) Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 154 Views

The crypto.createDiffieHellman(primeLength, [generator]) method creates a Diffie-Hellman key exchange object by generating a prime number of specified bit length. This is commonly used for secure key exchange between parties. Syntax crypto.createDiffieHellman(primeLength, [generator]) Parameters The parameters are described below: primeLength – The number of prime bits to generate. Must be a number. generator – Optional generator for creating the exchange key object. ...

Read More

How to group an array of objects by key in JavaScript

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

Suppose, we have an array of objects containing data about some cars like this: const arr = [ { 'make': 'audi', 'model': 'r8', 'year': '2012' }, { 'make': 'audi', 'model': 'rs5', 'year': '2013' }, { ...

Read More

Remove duplicates and map an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 670 Views

When working with arrays of objects, a common task is extracting unique values from a specific property. This tutorial shows how to remove duplicates and map an array to extract unique "name" values from objects. Problem Statement Suppose we have an array of objects like this: const arr = [ {id: 123, value: "value1", name: "Name1"}, {id: 124, value: "value2", name: "Name1"}, {id: 125, value: "value3", name: "Name2"}, {id: 126, value: "value4", name: "Name2"} ]; Note that some ...

Read More

crypto.randomBytes() Method in Node.js

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

The crypto.randomBytes() method generates cryptographically strong pseudo-random data in Node.js. This method ensures sufficient entropy before completion, typically taking only a few milliseconds to generate secure random bytes. Syntax crypto.randomBytes(size, [callback]) Parameters The parameters are described below: size – Specifies the number of bytes to generate. Must not exceed 2**31 - 1. callback – Optional callback function called if an error occurs. If omitted, the method runs synchronously. Asynchronous Example ...

Read More
Showing 2141–2150 of 6,519 articles
« Prev 1 213 214 215 216 217 652 Next »
Advertisements