Javascript Articles

Page 406 of 534

How to remove non-word characters in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 389 Views

To remove non-word characters in JavaScript, we use regular expressions to replace unwanted characters with empty strings. Non-word characters include symbols, punctuation, and special characters that aren't letters, numbers, or underscores. What are Non-Word Characters? Non-word characters are anything that doesn't match the \w pattern in regex. This includes symbols like !@#$%^&*(), punctuation, and special characters, but excludes letters (a-z, A-Z), digits (0-9), and underscores (_). Using Simple Regex Pattern The most straightforward approach uses the \W pattern, which matches any non-word character: function removeNonWordChars(str) { if ...

Read More

How to decode an encoded string in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 11K+ Views

In JavaScript, string decoding refers to converting encoded strings back to their original form. While escape() and unescape() were historically used, modern JavaScript provides better alternatives like decodeURIComponent() and decodeURI(). Using unescape() (Deprecated) The unescape() method decodes strings encoded by the escape() method. It replaces hexadecimal escape sequences with their corresponding characters. Syntax unescape(string) Example // Special character encoded with escape function var str = escape("Tutorialspoint!!"); document.write("Encoded : " + str); document.write(""); ...

Read More

How to parse an URL in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 429 Views

JavaScript provides several methods to parse URLs and extract their components like protocol, hostname, pathname, and query parameters. The modern approach uses the built-in URL constructor, while legacy methods involve creating DOM anchor elements. Using the URL Constructor (Modern Approach) The URL constructor is the standard way to parse URLs in modern JavaScript. It creates a URL object with all components easily accessible. const url = new URL("https://www.youtube.com/watch?v=tNJJSrfKYwQ"); console.log("Protocol:", url.protocol); console.log("Host:", url.host); ...

Read More

How to add two strings with a space in first string in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 5K+ Views

To concatenate two strings in JavaScript, we use the '+' operator. When the first string already contains a trailing space, we can directly concatenate without adding an explicit space. However, if there's no space, we need to add one manually between the strings. Method 1: First String Has Trailing Space When the first string already ends with a space, simple concatenation is sufficient: function concatenateStrings(str1, str2) { return (str1 ...

Read More

What is the use of Object.is() method in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 242 Views

The Object.is() method determines whether two values are strictly equal, providing more precise comparison than the regular equality operators. Syntax Object.is(value1, value2) Parameters value1: The first value to compare value2: The second value to compare Return Value Returns true if both values are the same, false otherwise. How Object.is() Determines Equality Two values are considered the same when they meet these criteria: Both are undefined or both are null Both are true or both ...

Read More

How many ways can a property of a JavaScript object be accessed?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 424 Views

JavaScript object properties can be accessed in two main ways: dot notation and bracket notation. Each method has its own use cases and advantages. Dot Notation The dot notation is the most common and readable way to access object properties when the property name is known at compile time. object.propertyName Bracket Notation The bracket notation uses square brackets with the property name as a string. This method is more flexible and allows dynamic property access. object["propertyName"] object[variableName] Example: Using Dot Notation var person = ...

Read More

How to check whether an array is a true array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 241 Views

In JavaScript, arrays are actually objects, which makes type checking tricky. When you use the typeof operator on an array, it returns "object" rather than "array", making it unreliable for array detection. The Problem with typeof The typeof operator cannot distinguish between arrays and plain objects since both return "object". Syntax typeof operand Parameters: The typeof operator takes an operand and returns a string indicating the data type of the operand. Example: typeof with Arrays and Objects var a = [1, 2, 5, ...

Read More

How to access nested json objects in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 15K+ Views

Accessing nested JSON objects in JavaScript involves navigating through multiple levels of object properties. Nested objects are objects contained within other objects, creating a hierarchical data structure. What are Nested JSON Objects? A nested JSON object has one or more objects as property values. This creates multiple layers that you need to traverse to access specific data. Using Dot Notation The most common way to access nested properties is using dot notation, where you chain property names with dots. Example 1: Single Level Nesting var person = ...

Read More

How to modify properties of a nested object in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

There are two methods to modify properties of nested objects in JavaScript. One is Dot notation and the other is Bracket notation. The functionality is the same for both methods, but they differ in their syntax and use cases. Let's discuss them in detail with practical examples. Dot Notation Method Dot notation is the most common way to access and modify nested object properties. Use this when property names are valid identifiers and known at compile time. Example In the following example, initially the value of property country is England. Using dot notation, the value ...

Read More

How to find duplicates in an array using set() and filter() methods in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

Finding duplicates in JavaScript arrays is a common task that can be accomplished using modern JavaScript methods. The Set() constructor and filter() method provide elegant solutions for removing duplicates without complex logic. Using Set() Method The Set() constructor automatically stores only unique values, making duplicate removal straightforward. When combined with the spread operator, it creates a new array with duplicates removed. Syntax let uniqueArray = [...new Set(originalArray)]; Example var dupNames = ['John', 'Ram', 'Rahim', 'Remo', 'Ram', 'Rahim']; var uniArr = [...new ...

Read More
Showing 4051–4060 of 5,340 articles
« Prev 1 404 405 406 407 408 534 Next »
Advertisements