Front End Technology Articles

Page 365 of 652

Where is _.pluck() in lodash version 4?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 483 Views

The _.pluck() method was removed from lodash version 4 because it provided the same functionality as _.map(). This change was part of lodash's effort to reduce redundancy and improve consistency. What _.pluck() Did In lodash 3.x, _.pluck() extracted property values from a collection of objects: // Lodash 3.x syntax (no longer available) _.pluck(objects, 'propertyName') Replacement: Using _.map() In lodash 4+, use _.map() with a property path string to achieve the same result: const _ = require('lodash'); const objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }]; ...

Read More

What is the replacement of lodash pluck() method?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 2K+ Views

Lodash's pluck() method was removed in version 4.0 because it provided the same functionality as the map() method. The pluck() method was used to extract property values from objects in an array. Using _.map() as Replacement You can replace _.pluck() with _.map() using the property shorthand syntax: import _ from 'lodash'; const objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }]; console.log(_.map(objects, 'a')); [1, 2, 3] Using Native Array.map() For modern JavaScript, you can use the native Array.map() method without lodash: const objects ...

Read More

Difference between application/x-javascript and text/javascript content types?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

When serving JavaScript files, choosing the correct MIME type is crucial for proper browser handling. Let's explore the differences between these content types and understand which one to use. text/javascript (Obsolete) The text/javascript content type was used in the early days of HTML but is now obsolete according to RFC 4329. While browsers still support it for backward compatibility, it should not be used in modern applications. // Server header (obsolete) Content-Type: text/javascript application/x-javascript (Experimental) application/x-javascript was an experimental content type, indicated by the "x-" prefix. The "x-" denotes non-standard or experimental MIME ...

Read More

Checking for co-prime numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 527 Views

Two numbers are said to be co-primes if there exists no common prime factor amongst them (1 is not a prime number). For example: 4 and 5 are co-primes 9 and 14 are co-primes 18 and 35 are co-primes 21 and 57 are not co-prime because they have 3 as the common prime factor We are required to write a function that takes in two numbers and returns true if they are co-primes otherwise returns false. Understanding Co-prime Numbers Two numbers are co-prime if their greatest common divisor (GCD) is 1. This means ...

Read More

Find even odd index digit difference - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 226 Views

We are required to write a JavaScript function that takes in a number and returns the difference of the sums of the digits at even place and the digits at odd place. Understanding the Problem Given a number, we need to: Sum all digits at even positions (0, 2, 4, ...) Sum all digits at odd positions (1, 3, 5, ...) Return the absolute difference between these sums Example For the number 345336: Position 0: 6 (even) Position 1: 3 (odd) Position 2: 3 (even) Position 3: 5 (odd) Position 4: 4 (even) ...

Read More

Sum all duplicate value in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 502 Views

We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index. For example − If the input array is − const input = [1, 3, 1, 3, 5, 7, 5, 4]; Then the output should be − const output = [2, 6, 7, 10, 4]; Using Map to Track and Sum Duplicates The most efficient approach is to use a Map to count occurrences and then multiply each unique value by its count: ...

Read More

Inverting signs in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 630 Views

We are required to write a JavaScript function that takes in an array of positive as well as negative Numbers and changes the positive numbers to corresponding negative numbers and the negative numbers to corresponding positive numbers in place. Let's write the code for this function — Example Following is the code — const arr = [12, 5, 3, -1, 54, -43, -2, 34, -1, 4, -4]; const changeSign = arr => { arr.forEach((el, ind) => { arr[ind] *= -1; ...

Read More

Recursive multiplication in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 436 Views

We need to write a JavaScript function that takes a nested array containing numbers, false values, zeros, and strings, then returns the product of all valid numbers. The function should ignore zeros and falsy values while recursively processing nested arrays. Problem Statement Given a nested array with mixed data types, we want to multiply only the truthy numeric values while ignoring zeros, null, undefined, false, and strings. Solution We'll use recursion to traverse nested arrays and multiply only valid numbers: const arr = [1, 5, 2, null, [ 2, 5, ...

Read More

Find Second most frequent character in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 659 Views

We are required to write a JavaScript function that takes in an array and returns the element that appears for the second most number of times. Let's say the following is our array: const arr = [1, 34, 4, 3, 2, 1, 4, 6, 4, 6, 5, 3, 6, 6]; The most frequent element is 6 (appears 4 times), but we want the second most frequent element, which is 4 (appears 3 times). Example const arr = [1, 34, 4, 3, 2, 1, 4, 6, 4, 6, 5, 3, 6, 6]; ...

Read More

Divide a string into n equal parts - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 697 Views

We are required to write a JavaScript function that takes in a string and a number n (such that n exactly divides the length of string). We need to return an array of string of length n containing n equal parts of the string. Let's write the code for this function − Example const str = 'this is a sample string'; const num = 5; const divideEqual = (str, num) => { const len = str.length / num; const creds = str.split("").reduce((acc, val) => { ...

Read More
Showing 3641–3650 of 6,519 articles
« Prev 1 363 364 365 366 367 652 Next »
Advertisements