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
Page 4 of 534
JavaScript 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 MoreWhat is nodeValue property in JavaScript HTML DOM?
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 MoreHow -Infinity is converted to Number in JavaScript?
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 MoreWhat will happen when [50,100] is converted to Number in JavaScript?
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 MoreHow to use JavaScript to set cookies for homepage only?
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 MoreHow to show image in alert box using JavaScript?
To show an image in alert box, try to run the following code. Here, an alert image is added to the custom alert box −Example function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes").unbind().click(function() { confirmBox.hide(); }); confirmBox.find(".yes").click(myYes); ...
Read MoreHow to customize the position of an alert box using JavaScript?
To customize the position of an alert box, use the CSS “top” and “left” properties. We have a custom alert box, which we’ve created using jQuery and styled with CSS.ExampleYou can try to run the following code to customize the position of an alert box − function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes").unbind().click(function() { confirmBox.hide(); ...
Read MoreWhy does the JavaScript void statement evaluate an expression?
The JavaScript void returns an expression to remove the side effect and return the undefined primitive value. This side effect may occur while inserting expression in a web page.Let’s see an example of the void. The void(0) can be used with hyperlinks to obtain the undefined primitive value, Example Understanding JavaScript void(0) Click me not once, but twice. We used JavaScript:void(0) above to prevent the page from reloading when the button is clicked the first time.The code will only ...
Read MoreWhat is the difference between an acronym and abbr tags?
In layman language, an acronym is a word formed by taking letters of each word in a phrase to form an abbreviation. Acronyms are a subset of abbreviations i.e. abbreviation is a shortened form of a word.The tag isn’t supported in HTML5 and is deprecated now. Do not use. To add abbreviation in HTML, use the tag. Both abbreviation and acronym are the shortened versions and are represented as a series of letters. Some of the examples include, "Mr.", "IST", "MRI", “NASA”, “ISRO” etc. ExampleYou can try to run the following code to add abbreviation in HTML. ...
Read More