Front End Technology Articles - Page 518 of 745

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

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

369 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 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

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

225 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

410 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 Object.is() method in JavaScript?

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

228 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

415 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

376 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

Advertisements