Object Oriented Programming Articles

Page 171 of 589

Validating email and password - JavaScript

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

Suppose, we have this dummy array that contains the login info of two of many users of a social networking platform − const array = [{ email: 'usman@gmail.com', password: '123' }, { email: 'ali@gmail.com', password: '123' }]; We are required to write a JavaScript function that takes in an email string and a password string. The function should return a boolean based on the fact whether or not the user exists in the database. Example Following is the code − ...

Read More

Get only specific values in an array of objects in JavaScript?

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

When working with arrays of objects in JavaScript, you often need to extract specific values based on certain criteria. This can be accomplished using several array methods like filter(), map(), and find(). Let's say we have the following array of student objects: var details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }]; Using filter() to Get Objects Meeting Criteria ...

Read More

Repeat even number inside the same array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 154 Views

We are required to write a JavaScript function that should repeat the even number inside the same array. Therefore, for example given the following array − const arr = [1, 2, 5, 6, 8]; We should get the output − const output = [1, 2, 2, 5, 6, 6, 8, 8]; Example Following is the code − const arr = [1, 2, 5, 6, 8]; const repeatEvenNumbers = arr => { let end = arr.length - 1; for(let i = ...

Read More

Fetch values by ignoring a specific one in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 426 Views

To ignore a specific value when fetching data from an array or object, use the logical NOT (!) operator in conditional statements to exclude unwanted values and retrieve only the ones you need. Using NOT Operator with Array of Objects The most common approach is to loop through your data and use the inequality operator (!=) to skip specific values: var customerDetails = [ { customerName: "John", customerAge: 28, customerCountryName: "US" }, ...

Read More

Convert a list of string coords into two float lists of Lat/Longitude coordinates in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 644 Views

When working with coordinate data in JavaScript, you often need to parse string coordinates and separate them into latitude and longitude arrays. This is common when processing GPS data or API responses. Input Data Format Let's start with a list of coordinate strings in "latitude, longitude" format: var listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"]; console.log("Input coordinates:"); console.log(listOfStrings); Input coordinates: [ '10.45322, -6.8766363', '78.93664664, -9.74646646', '7888.7664664, -10.64664632' ] Method 1: Using forEach with split() and map() This approach uses split() to separate coordinates and map(Number) to convert strings to ...

Read More

From a list of IDs with empty and non-empty values, retrieve specific ID records in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 285 Views

When working with arrays of objects containing IDs, you often need to filter records based on specific ID values. JavaScript's filter() method provides an efficient way to retrieve all objects matching a particular ID, even when the array contains empty or null ID values. Sample Data Let's work with the following array that contains both valid and empty ID values: var details = [ {id: 101, name: "John", age: 21}, {id: 111, name: "David", age: 24}, {id: 1, name: "Mike", age: 22}, ...

Read More

Display in console if Select list value contains a value from an array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 719 Views

In JavaScript, you can check if a selected dropdown value exists in an array using event listeners and array methods. This is useful for validation or conditional logic based on user selections. HTML Structure Let's start with a basic dropdown containing several names: John David Chris Mike Bob Carol Array to Check Against We'll define an array of names to compare with the selected value: ...

Read More

How do I check whether a checkbox is checked in jQuery?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 385 Views

To check whether a checkbox is checked in jQuery, you can use several methods. The most common approaches are using the .is(':checked') method, the .prop('checked') method, or implementing toggle functionality. Method 1: Using .is(':checked') The .is(':checked') method returns a boolean value indicating whether the checkbox is checked: Checkbox Check Example Check me Check Status ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 301 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

Get the first element of array in JavaScript

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

In JavaScript, there are several ways to get the first element of an array. The most common and efficient approaches include using bracket notation, the at() method, or destructuring assignment. Using Bracket Notation (Most Common) The simplest way is to access the element at index 0 using bracket notation: let fruits = ["apple", "banana", "orange"]; let firstFruit = fruits[0]; console.log(firstFruit); // Handle empty arrays let emptyArray = []; let firstElement = emptyArray[0]; console.log(firstElement); apple undefined Using the at() Method The at() method provides a modern alternative for accessing array ...

Read More
Showing 1701–1710 of 5,881 articles
« Prev 1 169 170 171 172 173 589 Next »
Advertisements