Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 16 of 80

How to access properties of an array of objects in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In JavaScript, accessing properties of objects within an array is a common task. Whether you're working with a single object or an array of objects, there are several methods to retrieve property values effectively. JavaScript objects are collections of key-value pairs called properties. When you have an array containing multiple objects, you need specific techniques to access the properties of each object. Let's explore the main approaches. Using Dot Notation Dot notation is the most straightforward way to access object properties when the property name is known and is a valid JavaScript identifier. The syntax is object.propertyName. ...

Read More

How to Compare Two Arrays in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 758 Views

In JavaScript, comparing arrays with == or === operators doesn't work as expected because they compare object references, not actual array contents. This article explores multiple effective methods to properly compare two arrays in JavaScript. When we try to compare arrays directly, JavaScript compares memory references rather than the array elements themselves, which typically results in false even for identical arrays. Why Direct Comparison Fails const arr1 = [1, 2, 3]; ...

Read More

How to print content of JavaScript object?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In this tutorial, we will learn to print the content of a JavaScript object. Objects are similar to variables, but they can contain many values. Javascript object values are written as key: value pairs, and each pair is separated by commas. It is used to access data from databases or any other sources. Following are the ways to print the content of JavaScript objects − Using the JSON.stringify() Method Using Object.values() Using a for-in loop Using JSON.stringify() Method The JSON.stringify() method converts JavaScript objects ...

Read More

How to merge two arrays in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will learn how to merge two arrays in JavaScript. In JavaScript, we can merge two arrays using different approaches. Here are the three most common methods: Using the Array concat() method Using the spread operator Using loop iteration Using the Array concat() Method The Array concat() method merges two or more arrays and returns a new array. This is one of the most popular methods for merging arrays in JavaScript. The method operates on an array, takes another array as a ...

Read More

How to set the image to be used as a border with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will learn how to set the image to be used as a border with JavaScript. The outline of an HTML element is called the border. The 'border-image' CSS property is used to set an image as the border around an element. It is a shorthand property for: border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat. To set the image to be used as a border with JavaScript we have different ways − Using the style.borderImage Property Using the style.setProperty Method Using the style.borderImage Property An element's ...

Read More

How to extend an existing JavaScript array with another array?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 3K+ Views

In this tutorial, let's find out how to extend an existing JavaScript array with another array. There are multiple methods to accomplish this task, and choosing the right one depends on whether you want to modify the original array or create a new one. Using Array push() Method with Spread Syntax The push() method adds elements to the end of an array and modifies the original array. When combined with the spread operator, it can extend an array with all elements from another array. Syntax array1.push(...array2) Example This method modifies the original ...

Read More

How to randomize (shuffle) a JavaScript array?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn different methods to randomize or shuffle a JavaScript array. Shuffling arrays is a common requirement in programming, useful for games, random sampling, or creating unpredictable sequences. Using the Fisher-Yates Algorithm The Fisher-Yates algorithm is the most reliable method for shuffling arrays. It iterates through the array from the last index to the first, swapping each element with a randomly selected element from the remaining unshuffled portion. Syntax for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + ...

Read More

How to set whether the image-border should be repeated, rounded or stretched with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 237 Views

This tutorial will teach us to set whether the border image should be repeated, rounded, or stretched with JavaScript. Use the borderImageRepeat property to set whether the image-border is to be repeated, rounded, or stretched. Borders are used to decorate or focus an element. You can define its width, color, and type of border. Various styles can be applied to the borders. But, these borders are without any special effects or any other designs. Using the border-image property, we can set an image as a border of an element. It does not look like a line. It will ...

Read More

How to display HTML element with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In this tutorial, we will learn how to display an HTML element using JavaScript. HTML elements are the components that make up an HTML format file. These components are in charge of constructing web pages and defining their content. In HTML, an element typically consists of a start tag, content, and a closing tag. Some HTML elements are − Starting Tag Content Ending Tag ...

Read More

How to convert Boolean to Number in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In JavaScript, Boolean values (true and false) can be converted to numbers (1 and 0 respectively) using several methods. This conversion is useful when performing mathematical operations or comparisons that require numeric values. JavaScript provides multiple approaches to convert Boolean values to numbers. Let's explore three effective methods with examples. Using the Number() Function The Number() function is the most explicit and readable way to convert Boolean values to numbers. It converts true to 1 and false to 0. Syntax let result = Number(booleanValue); Example ...

Read More
Showing 151–160 of 793 articles
« Prev 1 14 15 16 17 18 80 Next »
Advertisements