Found 8591 Articles for Front End Technology

Return correct value from recursive indexOf in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:36:35

375 Views

A computer pattern or idea called recursion is present in many programming languages, including JavaScript. It is a feature used to build a function that repeatedly calls itself, but with a smaller input each time, until the intended outcome of the code is realized. In this article, we will return the correct value from a recursive indexof() function in JavaScript. Let’s dive into the article for a better understanding. Accurate value from the recursive indexof() function The position of the first occurrence of a value in a string is returned by the indexOf() method. -1 is returned by the indexOf() ... Read More

ES6/ECMA6 template literals not working in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:48:00

1K+ Views

Template literals are a powerful and useful feature of the ECMAScript 6 (ES6) JavaScript language. However, there may be times when template literals do not work properly in your code. This article will discuss some common issues you may encounter with template literals, as well as potential solutions for resolving them. Additionally, we'll provide an overview of what template literals are and how they can be used to create more efficient and readable code. Template literals were known as template strings prior to ES6. Template literals are surrounded by the backtick (' ') character as opposed to quotes in ... Read More

JavaScript regex - How to replace special characters?

Yaswanth Varma
Updated on 21-Jun-2024 15:04:35

12K+ Views

Characters that are neither alphabetical nor numeric are known as special characters. Special characters are essentially all unreadable characters, including punctuation, accent, and symbol marks. Remove any special characters from the string to make it easier to read and understand. Before we jump into the article let’s have a quick view on the regex expression in JavaScript. Regex expression in JavaScript Regular expressions are patterns that can be used to match character combinations in strings. Regular expressions are objects in JavaScript. These patterns can be used with the exec() and test() methods of RegExp as well as the match(), matchAll(), ... Read More

Get the number of true/false values in an array using JavaScript?

AmitDiwan
Updated on 26-Oct-2020 11:25:52

2K+ Views

To get the number of true/ false values in an array, the code is as follows −var obj = [    {       isMarried: true    },    {       isMarried: false    },    {       isMarried: true    },    {       isMarried: true    },    {       isMarried: false    } ] function numberOfTrueValues(obj) {    var counter = 0;    for (var index = 0; index < obj.length; index++) {       if (obj[index].isMarried === true) {          counter++;     ... Read More

Is it possible to change the value of the function parameter in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:04:48

4K+ Views

In this article we are going to find out whetehr it is possibleto change the value of the function parameter in JavaScript. A function accepts a certain values as parameters an later while calling this function we need to pass values for these parameters as arguments. Typically a function definition contains the name of the function, parameters (optional) and the body of the function.Syntax Following is the syntax for function parameter − function Name(paramet1, paramet2, paramet3, paramet4) { // Statements } Yes, it is possible to change the value of the function parameter in JavaScript. ... Read More

Set object property in an array true/false, whether the id matches with any id from another array of objects in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:09:37

727 Views

The task we are going to perform in this article is ‘set object property in an array true/false whether the id matches with any if from another array of objects in JavaScript’. Before we jump into the article let’s have a glance at the object and array in JavaScript. An object in JavaScript is a separate entity having properties and a type. JavaScript objects have properties that specify their attributes. Multiple values can be kept in a single variable by using arrays. Compare that to a variable that only has room for one value. Each item in an array has ... Read More

Add class name in different li by pure in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:36:56

2K+ Views

A class serves as a model for building objects. Code is used to encapsulate data, so that it can be worked on. Although JS classes are based on prototypes, they also have some unique syntax and semantics that are not shared by ES5 classes. Let’s dive into the article to learn more about how to add class name in different li by pure in JavaScript. To add class, use forEach() along with classList.add(). The forEach() in JavaScript For each entry in an array, the forEach() method invokes a different function. When dealing with empty elements, this method is not ... Read More

Understanding the find() method to search for a specific record in JavaScript?

AmitDiwan
Updated on 26-Oct-2020 11:15:22

478 Views

To fetch a specific record, use find() with some condition.ExampleFollowing is the code −var obj=[    {       studentId:101,       studentName:"John"    },    {       studentId:102,       studentName:"Bob"    },    {       studentId:103,       studentName:"David"    } ] const result = obj.find(    (o) =>    {       return o.studentId === 102    } ); console.log(result);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo315.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo315.js { studentId: 102, studentName: 'Bob' }

Is there any way to check if there is a null value in an object or array in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:27:34

9K+ Views

Null values can be tricky to work with in JavaScript, but they are an important part of the language. In this article, we will discuss various ways you can check if there is a null value in an object or array in JavaScript. The null values display that no object value is present. It is intentionally set to show that a variable has been declared but has not yet been given a value. The primitive value is undefined, which is an unintended absence of any object value, which is comparable to null, that contrasts with the former. This is due ... Read More

Shortest syntax to assign properties from function call to an existing object in JavaScript

Yaswanth Varma
Updated on 18-Jan-2023 11:33:30

135 Views

In JavaScript, objects can be created and assigned properties in a variety of ways. One popular approach is to use the shortest syntax to assign properties from a function call to an existing object. In this article, we will explore how to use this technique and discuss some considerations when using it. An object in JavaScript is a separate entity having properties and a type. JavaScript objects can have properties that specify their attributes. Spread syntax (…) An iterable, such as an array or string, can be expanded in places where zero or more arguments or components are ... Read More

Advertisements