
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
Found 6710 Articles for Javascript

296 Views
Array.find()Array.find() is used to return value of first element in the array that satisfies provided testing condition(user given condition).If the provided testing condition fails then array.find() returns undefined.In the following example array.find() checks whether the price elements in array are more than the given testing price(12000). If the provided testing condition true then first value that passed the test will be executed, if not undefined will be executed. ExampleLive Demo var price = [3000, 21000, 28000, 20000, 15500]; function checkCost(cost) { return cost >= 12000; } document.getElementById("price").innerHTML = price.find(checkCost); Output21000

190 Views
JSON.parse()When the data is received from web server, the data is always a string .So to change it to the object, JSON.parse() method is used. Example Live Demo var obj = '{"name":"Jon", "age":20, "city":"Columbia"}'; var res = JSON.parse(obj); document.write(res); console.log(res); output[object object] {"name":"Jon", "age":"20", "city":"Columbia"}

226 Views
You can use below syntax for inserting an 8-byte integer in MongoDB through JavaScript shell −anyVariableName= {"yourFieldName" : new NumberLong("yourValue")};To display the above variable, you can use the variable name or printjson(). Following is the query to insert 8 byte integer in MongoDB −> userDetail = {"userId" : new NumberLong("98686869")}; { "userId" : NumberLong(98686869) }Let us display the above variable value using variable name. The query is as follows −> userDetailThis will produce the following output −{ "userId" : NumberLong(98686869) }Let us display the variable value using printjson() −> printjson(userDetail); This will produce the following output −{ "userId" : NumberLong(98686869) }

228 Views
JSON.stringify()If we need to send data to a web server the data should be a string.To change the object literal to string JSON.stringify() method should be used.For instanceExample-1 Live Demo var obj = {name:"rekha", age:40, city:"newyork"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON; Output{"name":"rekha","age":40,"city":"newyork"}Example-2 Live Demo var obj = {"name":"ramesh","age":30,"family": [{"mother":"geetha","father":"rao"}],"city":"berlin"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON; Output{"name":"ramesh","age":30,"family":[{"mother":"geetha","father":"rao"}],"city":"berlin"}

131 Views
Accessing Property Of An ObjectWithout objects there is no JavaScript. Everything such as boolean,numbers,functions etc are all objects.Accessing properties of an object is explained in the following method.Example-1 Live Demo myObj = {"name":"Ramesh","age":30,"family": [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"}; var res = myObj.family[0].mother; document.write(res); OutputGeethaExample-2 Live Demo myObj = {"name":"Ramesh","age":30,"family": [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"}; var res = myObj.city; document.write(res); OutputBerlin

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. Live DemoExample function minimum(value) { if (toString.call(value) !== "[object Array]") return false; return Math.min.apply(null, value); } document.write(minimum([6, 39, 55, 1, 44])); Output12) sort()Using sort() and compare functions we can write the elements in ascending or descending order, later on using length property we can ... Read More

1K+ Views
we can find the Maximum value of an array using Math.max() and sort() functions.1) Math.max()Math.max() function usually takes all the elements in an array and scrutinize each and every value to get the maximum value.It's methodology is discussed in the below example. Live DemoExample function maximum(value) { if (toString.call(value) !== "[object Array]") return false; return Math.max.apply(null, value); } document.write(maximum([6, 39, 55, 1, 44])); Output55.2) sort()Using sort and compare functions we can ... Read More

1K+ Views
Both the methods are used to add elements to the array.But the only difference is unshift() method adds the element at the start of the array whereas push() adds the element at the end of the array.1) push()Array.push() method is used to add an element at the end of an array like a queue .In the following example it is shown how to add an element using push() method Live DemoExample var cars = ["Benz", "Lamborghini", "Tata safari"]; cars.push("Ferrari"); document.write(cars); OutputBenz, Lamborghini, Tata safari, Ferrari2) unshift()Array.unshift() method is ... Read More

187 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