Articles on Trending Technologies

Technical articles with clear explanations and examples

How to determine if date is weekend in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 876 Views

In JavaScript, you can determine if a date falls on a weekend by using the getDay() method. This method returns 0 for Sunday and 6 for Saturday, making weekend detection straightforward. How getDay() Works The getDay() method returns a number representing the day of the week: 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday Basic Weekend Check Here's how to check if a specific date is a weekend: var givenDate = new Date("2020-07-18"); var currentDay = givenDate.getDay(); var ...

Read More

The Zombie Apocalypse case study - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 303 Views

A nasty zombie virus is spreading out in the digital cities. We work at the digital CDC and our job is to look over the city maps and tell which areas are contaminated by the zombie virus so the digital army would know where to drop the bombs. They are the new kind of digital zombies which can travel only in vertical and horizontal directions and infect only numbers same as them. We'll be given a two-dimensional array with numbers in it. For some mysterious reason patient zero is always found in north west area of the ...

Read More

How to convert PHP array to JavaScript array?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 3K+ Views

Converting PHP arrays to JavaScript arrays is essential when passing server-side data to client-side scripts. PHP's json_encode() function provides a reliable way to achieve this conversion for both single and multidimensional arrays. Syntax // PHP side $phpArray = array('value1', 'value2'); // JavaScript side var jsArray = ; Example: Converting Simple PHP Array Let's start with a simple PHP array containing user information: var arr = ; console.log(arr); // Output: ["Amit", "amit@example.com"] console.log(arr[0]); // Output: "Amit" ...

Read More

Prim's algorithm in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex. How Prim's Algorithm Works Let us look at an illustration of how Prim's algorithm works: 1. Choose any arbitrary node ...

Read More

How to toggle text with JavaScript?

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

Text toggling allows you to dynamically change displayed content based on user interaction. This is commonly used for showing/hiding information, switching between states, or creating interactive UI elements. Basic Toggle Example Here's a complete example that toggles between two text values when a button is clicked: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

How to count a depth level of nested JavaScript objects?

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

We have an array of objects, which further have nested objects like this − const arr = [{ id: 0, children: [] }, { id: 1, children: [{ id: 2, children: [] }, { id: 3, children: [{ id: 4, children: [] }] }] }]; ...

Read More

How can I get seconds since epoch in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 436 Views

To get seconds since epoch in JavaScript, you can use Date.getTime() which returns milliseconds since January 1, 1970 (Unix epoch), then divide by 1000 to convert to seconds. Syntax var date = new Date(); var epochSeconds = Math.round(date.getTime() / 1000); Method 1: Using Math.round() The most common approach uses Math.round() to handle decimal precision: var currentDate = new Date(); var epochSeconds = Math.round(currentDate.getTime() / 1000); console.log("Seconds since epoch:", epochSeconds); console.log("Type:", typeof epochSeconds); Seconds since epoch: 1594821507 Type: number Method 2: Using Math.floor() For exact truncation without ...

Read More

If ([] == false) is true, why does ([] || true) result in []? - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 591 Views

If we look closely at the problem statement, the difference between ([] == false) and ([] || true) is the following − In the first case, we are using loose conditional checking, allowing type coercion to take over. While in the second case, we are evaluating [] to its respective Boolean (truthy or falsy) which makes use of the function Boolean() instead of type coercion under the hood. Let's now unveil the conversions that happen behind the scenes in both cases. Case 1 - ([] == false) According to the MDN docs, when two data ...

Read More

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

With JavaScript how can I find the name of the web browser, with version?

Abhinaya
Abhinaya
Updated on 15-Mar-2026 385 Views

To find the name of the web browser with version in JavaScript, you can use the navigator object which provides information about the user's browser and system. Basic Browser Detection The traditional approach uses navigator.userAgent to detect browser types: Browser Detection Example var userAgent = navigator.userAgent; var opera = (userAgent.indexOf('Opera') != -1); var ie = (userAgent.indexOf('MSIE') != -1 || ...

Read More
Showing 11811–11820 of 61,304 articles
Advertisements