Thursday, 22 October 2015

How to convert the whole string to capital letter in Javascript


How to convert the whole string to capital letter in Javascript ?
toUpperCase--is use for making a string to capital letter
var str="This is a technical blog"
str=str.toUpperCase()
alert(str)
will show "THIS IS A TECHNICAL BLOG"

How to detect OS by javascript ?


How to detect OS by javascript ?

var oprating_system ;
oprating_system=' ';

if (navigator.appVersion.indexOf("X11")!=-1) oprating_system="UNIX";
if (navigator.appVersion.indexOf("Win")!=-1) oprating_system="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) oprating_system="MacOS";
if (navigator.appVersion.indexOf("Linux")!=-1) oprating_system="Linux";

What is JSON.parse ?

What is JSON.parse ?

Returns the Object corresponding to the given JSON text. Takes a well-formed JSON string and returns the resulting JavaScript object.

Example 1
        var obj = jQuery.parseJSON( '{ "name": "John" }' );
        alert( obj.name === "John" );


Example 2
var jsonString = '[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]';

var myData = JSON.parse(jsonString);

$(document).ready(function() {
    var $grouplist = $('#groups');
    $.each(myData, function() {
        $('<li>' + this.name + '</li>').appendTo($grouplist);
    });
});

Result :
Manchester GTUG
Manchester jQuery Group
Hybrid!

What is json.stringify ?

What is json.stringify ?

If the stringify method sees an object that contains a toJSON method, it calls that method, and stringifies the value returned. This allows an object to determine its own JSON representation.

Example 1.
       JSON.stringify([1,2,3,4,"open","the","door"]);
Result : produces "[1,2,3,4,"open","the","door"]"

Example 2.

var mangtug = {
        name: "Manchester GTUG",
        meetup: "First Monday of every month",
        tags: ["gtug", "google", "manchester", "madlab"]
    },
    manjquery = {
        name: "Manchester jQuery Group",
        meetup: "First Tuesday of every month",
        tags: ["jquery", "javascript", "jresig", "madlab"]
    },
    hybrid = {
        name: "Hybrid!",
        meetup: mangtug.meetup,
        tags: manjquery.tags
    };

var madlabGroups = [mangtug, manjquery, hybrid];

Result :

[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...