Javascript Articles

Page 4 of 534

What are the types of tags involved in javascript?

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

Html taga) The tag is used to define a client-side script.b) The tag  contains scripting statements or an external script file.JavaScript code must be keep in script tag.Let's see the use of the tag. For suppose declare the variable outside the script tag.    var a = 1;    var b = 2;    var c = a + b; document.getElementById("tag").innerHTML = c; Output3

Read More

How to find the minimum value of an array in JavaScript?

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

We can find the minimum value of an array using Math.min() and sort()1) Math.min() Math.min() function usually takes all the elements in an array and scrutinize each and every value to get the minimum value.It's methodology is discussed in the below example.    var numbers = [6, 39, 55, 1, 44];    document.getElementById("min").innerHTML = numbers;    function myFunction() {       numbers.sort(function(a, b){return b - a});    document.getElementById("min").innerHTML = numbers;    document.write(numbers[numbers.length-1]); } After running the program the out put will be shown as in  the following imageOutputOn clicking the click me button above ...

Read More

Traversing Diagonally in a matrix in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 928 Views

Problem:We are required to write a JavaScript function that takes in a square matrix (an array of arrays having the same number of rows and columns). The function should traverse diagonally through that array of array and prepare a new array of elements placed in that order it encountered while traversing.For example, if the input to the function is −const arr = [    [1, 2, 3],    [4, 5, 6],    [7, 8, 9] ];Then the output should be −const output = [1, 2, 4, 7, 5, 3, 6, 8, 9];Exampleconst arr = [    [1, 2, 3],   ...

Read More

Common element with least index sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 237 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument.Our function should find out the common element in arr1 and arr2 with the least list index sum. If there is a choice tie between answers, we should output all of them with no order requirement.For example, if the input to the function is−const arr1 = ['a', 'b', 'c', 'd']; const arr2 = ['d', 'a', 'c'];Then the output should be −const output = ['a'];Output ExplanationSince 'd' and 'a' are common in both the arrays the index ...

Read More

JavaScript One fourth element in array

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 185 Views

ProblemJavaScript function that takes in an array of integers sorted in increasing order, arr.There is exactly one integer in the array that occurs more than one fourth times (25%) of the times, our function should return that number.For example, if the input to the function is −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9];Then the output should be −const output = 7;Exampleconst arr = [3, 5, 5, 7, 7, 7, 7, 8, 9]; const oneFourthElement = (arr = []) => {    const len = arr.length / 4;    const search = (left, right, target, direction = 'left') => {       let index = -1       while (left

Read More

How exactly does <script defer=“defer”> work?\\n

Samual Sam
Samual Sam
Updated on 11-Mar-2026 315 Views

The defer attribute is used to specify that the script execution occurs when the page loads. It is used only for external scripts and is a boolean attribute.ExampleThe following code shows how to use the defer attribute:                 The external file added will load later, since we're using defer    

Read More

What is nodeValue property in JavaScript HTML DOM?

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 336 Views

The nodeValue property is used to get the node value. You need to specify the node.ExampleYou can try to run the following code to learn how to get nodeValue property.           Get the node value       Demo Button Text                var val = document.getElementsByTagName("BUTTON")[0];          var res = val.childNodes[0].nodeValue;          document.write("Node Value: "+res);          

Read More

How -Infinity is converted to Number in JavaScript?

Monica Mona
Monica Mona
Updated on 11-Mar-2026 268 Views

Use the Number() method in JavaScript to convert to Number. You can try to run the following code to learn how to convert -Infinity Number in JavaScript.Example           Convert -Infinity to Number                var myVal = -Infinity;          document.write("Number : " + Number(myVal));           OutputConvert -Infinity to Number Number : -Infinity

Read More

What will happen when [50,100] is converted to Number in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 11-Mar-2026 160 Views

Use the Number() method in JavaScript to convert to Number. You can try to run the following code to learn how to convert [50, 100] to Number in JavaScript − Example Live Demo Convert [50,100] to Number var myVal = [50,100]; document.write("Number: " + Number(myVal));

Read More

How to use JavaScript to set cookies for homepage only?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 370 Views

To set cookies for a homepage, add the page to the homepage itself.ExampleYou can try to run the following code to set cookies                                                  Enter name:                    

Read More
Showing 31–40 of 5,339 articles
« Prev 1 2 3 4 5 6 534 Next »
Advertisements