Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2618 of 3363
212 Views
SortingSorting is nothing but displaying elements in ascending or descending order. Array.sort() function is to sort the array according to the compare() function in JavaScript.a) In the given program we are going to sort the array by age property in descending order. Live DemoExample var persons = [ { name: 'rajesh', birthdate: 1845, death: 1875 }, { name: 'Bharat', birthdate: 1909, death: 1917}, { name: ... Read More
2K+ Views
Reversing an array means that we are reversing the order of elements present in the array, but not the array itself. In simpler terms, the element at 0th index will be shifted to the last index of the array and vice versa. There are various ways to reverse an array in JavaScript in this article, we will look into these in detail − Using the reverse() method() The reverse() method in JavaScript reverses the order of the array elements. The first element in the array is swapped with the last element, the second element is swapped with the second last ... Read More
2K+ Views
To find the cubes of elements of given array we need to run a for loop to access each and every element and we need to use "=" operator to replace elements with their cubes.To get the desired values the below steps need to be followed.Steps1) Declared an array a = [1, 2, 3, 4, 5]2) For loop was introduced to access each and every element in the array(a[i]).3) Inside for loop "=" operator is used to replace the element with their cubic values(a[i]*a[i]*a[i]).so, from the above steps the output obtained will be 1, 8, 27, 64, 125.By following the ... Read More
232 Views
JavaScript Bitwise NOT Live DemoExample document.getElementById("not").innerHTML = ~ 13; Output-14Explanation: It gives 0 for 1 and 1 for 0.The above result is 14.JavaScript Bitwise leftshift operator Live DemoExample document.getElementById("left").innerHTML = 5
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. Live DemoExample var a = 1; var b = 2; var c = a + b; document.getElementById("tag").innerHTML = c; Outputvar a = 1For suppose, let the variable be declared inside the script tag. Live DemoExample var a = 1; var b = 2; var c = a + b; document.getElementById("tag").innerHTML = c; Output3
241 Views
JavaScript TagsThe html script tag wants the browser to get a script between them. We can expect the scripts to be in the following places. 1.The script can be placed in html's head tag 2.Within Html's body tag. 3.As an external file. Most importantly client side scripts such as JavaScript are placed in script tags.demonstration code Live Demo This example writes "JavaScript is not java" into an HTML element with id="script" document.getElementById("imp").innerHTML = "JavaScript is not java"; OutputThis example writes "JavaScript is not java" into an HTML element with id="script" JavaScript is not javaExplanationEvery JavaScript code should be in ... Read More
3K+ Views
There are 4 ways to display the output in JavaScript. a) Displaying the output in HTML elements, using innerHTML attribute. Live DemoExample document.getElementById("display").innerHTML = 10 + 10; Output20.b) Displaying the output using document.write(). Live DemoExample document.write(2 + 3); Output5c) Displaying the output through console.log(). Live DemoExample console.log(2 + 3); In debugger console, the output5.d) Displaying the output through alert box. Live DemoExample 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.
74K+ Views
In JavaScript, the object is a real-time entity that contains properties and methods. In simple words, we can say that object is an instance of a class. It stores the data in the form of key and value pairs. The keys are usually referred to as properties and the values are referred to as property values. There are two ways to define an object in JavaScript. Syntax var obj = new Object(); (or) var obj = {property1: value, property2 : value2 …….} Using dot (.) operator In JavaScript, using the dot (.) operator we can access a variable ... Read More
212 Views
add and assignment(+=) operatorThe add and assignment(+=) operator reduces the code little bit.It may not much influential in small codes whereas coming to long codes it's use can't be ignored. Live DemoExample var tot = 0; var a = [1,45,78,9,78,40]; for(var i = 0; i