Found 8862 Articles for Front End Technology

How to hide/show HTML elements in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

Using Css style we can hide or show HTML elements in javascript. Css provides properties such as block and none to hide/show the HTML elements.Hiding an elementExampleIn the following example when the "Hideme" button has clicked the text in the paragraph tag has been disappeared as shown in the output.Live Demo    Using JavaScript to hide HTML elements.    

How to find duplicates in an array using set() and filter() methods in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

Removing duplicatesTo remove duplicates in an array we have many logical methods, but advanced javascript has provided some methods so that the task of removing duplicates has become very simple. Some of those methods are set() and filter(). For better understanding lets' discuss each method individually.Set()The important use of the set() method is that it only allows unique values. In other words, it will automatically remove duplicates and makes the task easy for us. The Set() method won't take any logical approach in removing duplicates.Example In the following example, the duplicates in the provided array have been removed without any ... Read More

How to convert a string in to a function in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:57:31

6K+ Views

To convert a string in to function "eval()" method should be used. This method takes a string as a parameter and converts it into a function.syntaxeval(string);ExampleIn the following example, in a string itself, a property called 'age' is assigned with a function. Later on, using eval() function the property age is converted into a function and displayed as shown in the output. Live Demo    var string = '{"name":"Ram", "age":"function() {return 27;}", "city":"New jersey"}';    var fun = JSON.parse(string);    fun.age = eval("(" + fun.age + ")");    document.write(fun.name + " "+ "of Age" + " "+ fun.age()+ " " + "from ... Read More

How to convert a string in to date object in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:48:18

262 Views

To convert a string in to date object Date() method should be used. This method creates a date instance that represents a single moment in time in a platform-independent format.ExampleIn the following example a string named "str" is initially parsed using JSON.parse() method and then converted in to date object using Date() method.Live Demo     var str = '{"name":"Ram", "DOB":"1980-11-1", "country":"India"}';    var dateObj = JSON.parse(str);    dateObj.DOB = new Date(dateObj.DOB);    document.write(dateObj.DOB); OutputThu Nov 01 0198 00:00:00 GMT+0553 (India Standard Time)

How to delete a property of an object in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:49:20

332 Views

To delete a property of an object, delete key word should be used. Delete key word can be used with both the methods such as Dot method and Bracket method.syntaxdelete object.property;ExampleIn the following example initially when the property "country" is executed its value "England" is displayed in the output. But when that property is deleted using delete keyword, instead of "England", undefined is displayed as shown in the output.Live Demo    var txt = "";    var person = {       "name":"Ram",       "age":27,       "address": {          "houseno" : 123,   ... Read More

How to modify properties of a nested object in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

3K+ Views

There are two methods to modify properties of nested objects. One is Dot method and the other is Bracket method. The functionality is same for both the methods, but the only difference is their notation. lets' discuss them in detail.Dot methodExampleIn the following example initially the value of property country is England. But using Dot notation the value is changed to India.Live Demo    var person;    var txt = '';    person = {       "name":"Ram",       "age":27,       "address": {          "houseno":123,          "streetname":"Baker street",     ... Read More

How to access nested json objects in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:42:50

13K+ Views

Accessing nested json objects is just like accessing nested arrays. Nested objects are the objects that are inside an another object.In the following example 'vehicles' is a object which is inside a main object called 'person'. Using dot notation the nested objects' property(car) is accessed.Example-1Live Demo    var person = {       "name":"Ram",       "age":27,       "vehicles": {          "car":"limousine",          "bike":"ktm-duke",          "plane":"lufthansa"       }    }    document.write("Mr Ram has a car called" + " " + person.vehicles.car); ... Read More

How to check whether an array is a true array in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:28:55

123 Views

In javascript, arrays are not true arrays. They are javascript objects. So when we try to know their type using typeof() operator the displayed output will be object.Syntaxtypeof(operand);parameters - typeof() operator takes an operand and returns the data type of the operand. In the following example even though variable 'a' is an array, the typeof() operator returns the output as object because in general every array is an object.ExampleLive Demo    var a = [1, 2, 5, "hello"];    document.write(typeof(a));    var b = {};    document.write("");    document.write(typeof(b)); Outputobject objectUnlike typeof() operator, Array.isArray() checks whether the passed parameter ... Read More

How many ways can a property of a JavaScript object be accessed?

vineeth.mariserla
Updated on 29-Jun-2020 11:33:58

284 Views

 An object property can be accessed in two ways. One is .property and the other is [property].Syntax-1Object.property;Syntax-2Object["property"];For better understanding, lets' look at the following example.In the following example an object called 'person' is defined and its properties were accessed in a dot notation.ExampleLive Demo var person = {    firstname:"Ram",    lastname:"kumar",    age:50,    designation:"content developer" }; document.write(person.firstname + " " + "is in a role of" + " " + person.designation); OutputRam is in a role of content developerIn the following example the properties of an object 'person' were accessed in bracket notation.ExampleLive Demo ... Read More

What is the use of Atomics.store() method in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

119 Views

Atomics.store()Atomics.store() is an inbuilt method that is used to store a specific value at a specific position in an array. This method accepts an Integer typed array, index and the value as arguments.SyntaxAtomics.store(typedArray, index, value);Parameterstyped array - it the shared integer typed array that we need to modify.index - It is the position in the array where we are going to store the value.value - it is number we want to store.Whenever we want to store a value at a specific place and wants to return the stored value then Atomics.store() is used.One should note that Atomics are used with SharedArrayBuffer(generic fixed-length binary ... Read More

Advertisements