Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Found 5,338 articles
How to Title Case a sentence in JavaScript?
Title Case a sentence in javascriptIt is nothing but converting first element of all the words in a sentence in to uppercase while the other elements remain in lowercase. The provided string(sentence) may contains a bunch of lowercase and uppercase elements. So we need an algorithm to Title Case the provided string.AlgorithmDivide all the words in the sentence individually. This task can be achieved by using string.split() method.Convert all the elements in each and every word in to lowercase using string.toLowerCase() method. Loop through first elements of all the words using for loop and convert them in to uppercase. After converting, ...
Read MoreExplain about logical not(!) operator in detail with example in javascript?
NOT operatorThe logical NOT operator gives true for false values and false for true values. var x = 200; var y = 300; document.getElementById("logical").innerHTML = !(x < y) + "" + !(x > y); Outputfalse true
Read MoreHow to display output in javascript?
There are 4 ways to display the output in JavaScript. a) Displaying the output in HTML elements, using innerHTML attribute. alert(2 + 3); In alert window box, the output5In case of handling json strings, or some other big data console.log is the best choice.
Read MoreWrite a number array and add only odd numbers?
Odd number summation using JavaScript. var tot = 0; var a = [1,45,78,9,78,40,67,76]; for(var i = 0; i
Read MoreWhat are the types of tags involved in javascript?
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 MoreHow to find the minimum value of an array in JavaScript?
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 MoreTraversing Diagonally in a matrix in JavaScript
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 MoreCommon element with least index sum in JavaScript
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 MoreJavaScript One fourth element in array
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 MoreHow exactly does <script defer=“defer”> work?\\n
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