background preloader


Facebook Twitter

Mastering JSON ( JavaScript Object Notation ) Filed: Tue, Apr 10 2007 under Programming|| Tags: JSON javascript objects ajax Widely hailed as the successor to XML in the browser, JSON aspires to be nothing more than a simple, and elegant data format for the exchange of information between the browser and server; and in doing this simple task it will usher in the next version of the World Wide Web itself.

Mastering JSON ( JavaScript Object Notation )

The Object: An Introduction Behold, an Object… var myFirstObject = {}; It may not look like much, but those squiggly braces have the potential to record every bit of information humanity has ever gathered, and express the most complex programs computer scientists can dream up. Creating A New Object The old way to create a new object was to use the new keyword. var myJSON = new Object(); This method has been deprecated now in favor of simply defining an empty object with squigly braces… var myJSON = {}; Objects as Data At its most base level a Javascript Object is a very flexible and robust data format expressed as name/value pairs.

A re-introduction to JavaScript. IntroductionEdit Why a re-introduction?

A re-introduction to JavaScript

Because JavaScript is notorious for being the world's most misunderstood programming language. It is often derided as being a toy, but beneath its layer of deceptive simplicity, powerful language features await. JavaScript is now used by an incredible number of high-profile applications, showing that deeper knowledge of this technology is an important skill for any web or mobile developer. It's useful to start with an overview of the language's history. Several months later, Microsoft released JScript with Internet Explorer 3.

Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on. Hash Tables in Javascript. Javascript is a prototype-based object-oriented language.

Hash Tables in Javascript

In JavaScript, all non-scalar objects behave as associative arrays, a mapping from property keys to values. The keys and values can be scalars, objects or functions. This tutorial demonstrates how to provide a hash table wrapper around these native objects that avoids stepping on the built-in properties of a JavaScript object and thus makes it more consistent. Introduction A hash table is a permutation of an associative array (i.e. name => value pairs). In JavaScript, all non-scalar objects behave as associative arrays. A short example of an associative array (hash table) in JavaScript is as follows: TIP: Feel free to replace alert() with console.log() if it's supported by your browser (Chrome, Firefox with FireBug, etc). Just as in PHP, the 'foreach' contruct is used to run through the array, doing something for each key => value pair. Alert('size of hash table ' + h.length); Hmm. Fundamentals = 1; Summary Attributions.

Understanding javascript arrays - online javascript primer - creating and storing values in javascript arrays. An array can be regarded as a set of variables.

understanding javascript arrays - online javascript primer - creating and storing values in javascript arrays

This does not mean that the variables in an array are related to each other; they are still separate entities in themselves. Arrays helps us group variables, which we plan to use for a particular purpose because accessing their values becomes a lot easier this way. Consider the following table: To store these city names, we can either employ different variables such as city1, city2, city3 ... or insert these values into an array. Let's see how we make an array. var city = new Array(); Each array is initialized using the new keyword with the Array() construct (Isn't this similar to using Date()?).

City[0] = "New York"; city[1] = "London"; city[2] = "New Delhi"; city[3] = "Sydney"; city[4] = "Tokyo"; city[5] = "Moscow"; city[6] = "Lima"; Each variable in an array begins with the array name followed by a numeric value contained in a pair of square brackets. JavaScript allows us to write the array initialization and assignment statements as one. A JavaScript Primer in Four Parts. JavaScript Primers, Tutorials and Scripts from HTMLGoodies. JSDB: JavaScript for databases.