Javascript Articles

Page 116 of 534

Merge sort vs quick sort in Javascript

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 767 Views

In this article, we are going to discuss about the differences between merge sort and quick sort in JavaScript with appropriate examples. Merge sort and Quick sort are used to sort the elements, but the approach is different. Both Merge sort and quick sort are based on Divide and Conquer Strategy. Merge sort It is a stable sorting algorithm. In the merge sort, it follows a recursive approach that repeatedly splits the array into half until no more division is possible i.e., the array either remains empty or has a single element. Then by comparing the two small array elements ...

Read More

d vs D in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 3K+ Views

This article discusses about \d vs\ D in JavaScript regex. The \d and \D meta characters are used to match the characters of a given string. \d and \D are different from each other. \d (character) is equivalent to [0-9] that means it matches any single number. The characters that are not matched by the \d are matched by the \D. \D is equivalent to [^0-9] that means it matches any character other than number. Both \d and \D are completely inverse to each other. To match a string with a pattern, the possible methods are: string.match(pattern), string.search(pattern), pattern.exec(string), pattern.test(text). ...

Read More

w vs W in JavaScript regex?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 4K+ Views

This article discusses about the \w vs \W in JavaScript regex. The \w and \W meta characters are used to match the characters of a given string. \w and \W are different from each other. \w (character) is equivalent to [a-zA-Z0-9_] that means it matches any single letter, number, or underscore. The characters that are not matched by the \w are matched by the \W. \W is equivalent to [^a-zA-Z0-9_] that means it matches any character other than letter, number and underscore. To match a string with a pattern, the possible methods are: string.match(pattern), string.search(pattern), pattern.exec(string), pattern.test(text). We use match ...

Read More

Super keyword in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 1K+ Views

In this article, we are going to discuss about the super keyword in JavaScript with suitable examples. The Super keyword is basically used in Object Oriented Programming. The Super keyword is used to call parameters and functions of an object’s parent. There are times a parent class and sub class can have same method names and parameter names. In those case, to avoid confusion between the parent class and sub class method names or parameter names, super keyword is used. In order to use a Super keyword, the child method must extend the parent class method. Syntax The syntax to ...

Read More

Execute digits in even places in a JavaScript array?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 200 Views

In this article, the given task is to execute digits in even places in a JavaScript array with suitable examples. To execute the digits in even places in a JavaScript array, we need to get the starting index of the array and we need to loop through it by checking whether the index is at odd place or even place. Using the filter() Method: This method will create a new array filled with elements that pass a test provided by a specified function. This method doesn’t execute the function for empty elements and this method do not modify the original ...

Read More

First and last child node of a specific node in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 860 Views

In this article we are going to learn about the first and last child node of a specific node in JavaScript along with suitable examples. To get the first and last child node of a specific node, there are existing properties called firstChild, lastChild, firstElementChild and lastElementChild. The difference between the property of firstChild and firstElementChild is that in contrast to firstElementChild, firstChild treats both text and comments contained within html elements as children. The firstChild also considers the whitespace in the text. The same is applicable for lastChild and lastElementChild. To get the first child of a list The ...

Read More

Sibling of a list element in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 6K+ Views

In this article, we are going to learn about the sibling of a list element in JavaScript with suitable examples. To find the sibling of a list element in JavaScript, there is an existing property called nextSibling. The nextSibling property returns the next node on the same tree level. The nextSibling returns a node object and it is a read-only property. Note − The nextSibling propery returns the next sibling node: An element node, a comment node, a text node. The whitespaces in between the elements are also considered as text nodes. Now, Let’s look into the syntax and usage ...

Read More

Insert a specified element in a specified position in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 2K+ Views

The given task to perform in this article is to insert a specified element in a specified position in JavaScript. The Javascript has provided "insertAdjacentElement()" to insert an already existing element in a specified position. There are four specified legal positions. The first position is ‘afterbegin’ (After the beginning of the element (first child)), the second is ‘afterend’ (After the element), third is ‘beforebegin’ (Before the element) and the fourth legal position is ‘beforeend’ (Before the end of the element (last child)). If there are multiple elements with the same name, then use indexes to access them as we access ...

Read More

Insert a specified HTML text into a specified position in the JavaScript document?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 1K+ Views

In this article, we are going to learn how to insert a specified HTML text into a specified position in the JavaScript document with suitable examples. There is an existing method in the JavaScript to insert a specified HTML text into a specified position in the JavaScript document i.e. insertAdjacentHTML() method. There are four specified legal positions. The first position is ‘afterbegin’, the second is ‘afterend’, third is ‘beforebegin’ and the fourth legal position is ‘beforeend’. Let’s use the above discussed specified legal postions in the examples below. Syntax The syntax to insert a specified HTML text into a specified ...

Read More

An element inside another element in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 10K+ Views

In this article, we are going to discuss about an element inside another element in JavaScript with suitable examples. In JavaScript to access an element within another element i.e.., the inner element, we use ‘.’ property. We can also check whether an element is present within another element or not using contains() method. This method either returns true or false. Let’s look into the possible ways to check an element inside another element with appropriate examples further in this article. Syntax The syntax to access an element inside another element is − document.getElementById(‘IDname’).getElementsByTagName(‘Tag’)[i].innerHTML; Where, IDname is the name ...

Read More
Showing 1151–1160 of 5,338 articles
« Prev 1 114 115 116 117 118 534 Next »
Advertisements