Over a million developers have joined DZone.

o - JS Library for Object Manipulation

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

o - is simple lightweight JavaScript library for basic object manipulation. Compressed and gzipped weights around 0,5 kb. It should work on IE 5.5 and latter. Also there is lite version that doesn't make hasOwnProperty check that will run faster and with less code.

Lately I was having fun making some JavaScript projects like Object Auto Documentation https://github.com/vladocar/AutoObjectDocumentation and Multiple object extend pattern in JavaScript http://www.vcarrer.com/2011/06/multiple-object-extend-pattern-in.html that are both object related.

When I was working on Object Auto Documentation I realized that can be handy if I had small library for dealing exclusively with JS objects.

That is how the idea for this library was born. Basically this library is nothing new or glamorous is just the tool I needed. The library contains methods like adding, removing values in the object, extracting object keys and values, object extending and cloning, transforming the object to JSON and JSON to object and many more..

The goal of this JavaScript is to make fast object interrogation without many error and property checking. From the primary tests I made this library should work even in IE 5.5. If you are using toJSON and toObject methods you should also include Douglas Crockford JSON.js file.

I also included the lite version that is basically the same code only without hasOwnProperty verification for speed gain.

One thing that surprised me is the native Object.keys method for extracting values is slower than for in loop method. Here are some speed tests that I find on jsperf.com http://jsperf.com/object-keys-iteration/3 and http://jsperf.com/object-keys-vs-for-in-for-values/2 .

I decided to implement the native Object.keys method for modern browsers and for in loop method for older browsers, in many browsers the native method is slower then for in method but probably the Object.keys will get some speed optimization in the future browsers. If you are using o-lite.js you will experience the pure velocity of .keys and .values method.

This library is inspired by underscore.js with the main focus on JavaScript Objects. The speed in this library is achieved by simply not doing any kind of error check. That means that you should do all the error checks outside of the library or modify the library (it is very easy because there are few lines of code) or be aware what this library does and how it’s made.

Here are the list of all the methods with examples.

The structure of the library (Auto Documentation)


Download the library on GitHub

Fell free to suggest code and speed improvements and also to suggest new methods for exploring the JavaScript Object.

From http://www.vcarrer.com/2011/08/o-js-library-for-object-manipulation.html

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}