Front End Technology Articles - Page 578 of 860

How to access nested json objects in JavaScript?

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

14K+ 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

196 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

386 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

207 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

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

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

202 Views

Object.is()Object.is() is used to check whether two values are same or not. Two values are same when they have the following criteria. Either both the values are undefined or null .Either both are true or false.Both strings should be of same length, same characters and in same order.The polarities of both the values should be equal.Both the values can be NaN and should be equal.syntaxObject.is(val1, val2);It accepts two parameters and scrutinize whether they are equal or not. If equal gives out true as output else false as output.There is a small difference between Object.is() and "==" that is when comparing +0 and -0, the former results false whereas the latter results true. ... Read More

How to add two strings with a space in first string in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:10:23

5K+ Views

To add two strings we need a '+' operator to create some space between the strings, but when the first string itself has a space with in it, there is no need to assign space explicitly. In the following example since the string 'str1' has a space with in it, just only concatenation without space is adequate to add both the strings.ExampleLive Demo           function str(str1, str2) {          return (str1 + str2);       }       document.write(str("tutorix is the best ", "e-learning platform"));     Outputtutorix is the best ... Read More

How to parse an URL in JavaScript?

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

398 Views

Parsing an URLIt is very simple to parse an URL in javascript by using DOM method rather than Regular expressions. If regular expressions are used then code will be much more complicated. In DOM method just a function call will return the parsed URL. In the following example, initially a function is created and then an anchor tag "a" is created inside it using a DOM method. Later on the provided URL was assigned to the anchor tag using href. Now, when function returns the parts of the URL, it tries to return the parsed parts as shown in the output. ... Read More

How to decode an encoded string in JavaScript?

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

11K+ Views

DecodingIn JavaScript, to decode a string unescape() method is used. This method takes a string, which is encoded by escape() method, and decodes it. The hexadecimal characters in a string will be replaced by the actual characters they represent using unescape() method.Syntaxunescape(string)ExampleIn the following the two exclamation marks have converted to hexadecimal characters using escape() method. Later on those marks were decoded in to their natural characters using unescape() method. Live Demo    // Special character encoded with escape function    var str = escape("Tutorialspoint!!");    document.write("");    document.write("Encoded : " + str);    // unescape() function    document.write("Decoded ... Read More

How to remove non-word characters in JavaScript?

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

351 Views

Removing non-word charactersTo remove non-word characters we need to use regular expressions. The logic behind removing non-word characters is that just replace the non-word characters with nothing('').ExampleIn the following example there are many non-word characters and in between them there exists a text named "Tutorix is the best e-learning platform". So using regular expressions the non-word characters were replaced with nothing('') so as to get the word characters as the output.Live Demo    function remNonWord (string) {       if ((string===null) || (string===''))       return false;       else       string = ... Read More

What is the use of weakSet.has() method in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 09:49:47

182 Views

weakSet.has()This is an inbuilt function in javascript which is used to return a boolean value on scrutinizing whether an object is present in weakSet or not. The weakSet object lets you store weakly held objects in a collection.SyntaxweakSet.has(obj);ArgumentsFrom the above line of code,  weakSet.has() accepts a parameter 'obj' and checks whether the parameter is present in the provided weakSet or not.Returning valueBased on presence of value, whether it is in weakSet or not, the weakSet.has() method returns a boolean output. If the value is present then true will be returned else false will be returned.Example-1In the following example weakSet.has() checks whether the object(user provided) 'object1' is ... Read More

Advertisements