Top "Object-literal" questions

An object literal is a comma separated list of name value pairs wrapped in curly braces.

How can I add a key/value pair to a JavaScript object?

Here is my object literal: var obj = {key1: value1, key2: value2}; How can I add field key3 with value3 to …

javascript object-literal
How to create an array of object literals in a loop?

I need to create an array of object literals like this: var myColumnDefs = [ {key:"label", sortable:true, resizeable:true}, {key:"…

javascript arrays object-literal
Adding/removing items from a JavaScript object with jQuery

I have a JavaScript object as follows: var data = {items: [ {id: "1", name: "Snatch", type: "crime"}, {id: "2", name: "Witches of Eastwick", …

javascript jquery object-literal
Dynamically Add Variable Name Value Pairs to JSON Object

I have a json object full of ips like var ips = {} I then add ip objects to this object like …

javascript object object-literal
How to use a variable for a key in a JavaScript object literal?

Why does the following work? <something>.stop().animate( { 'top' : 10 }, 10 ); Whereas this doesn't work: var thetop = 'top'; <something&…

javascript jquery variables properties object-literal
JavaScript property access: dot notation vs. brackets?

Other than the obvious fact that the first form could use a variable and not just a string literal, is …

javascript syntax object-literal
Self-references in object literals / initializers

Is there any way to get something like the following to work in JavaScript? var foo = { a: 5, b: 6, c: this.…

javascript object-literal
How to fill a Javascript object literal with many static key/value pairs efficiently?

The typical way of creating a Javascript object is the following: var map = new Object(); map[myKey1] = myObj1; map[myKey2] = …

javascript object-literal static-initialization
create object using variables for property name

Is it at all possible to use variable names in object literal properties for object creation? Example function createJSON (propertyName){ …

javascript properties object-literal
Use a concatenated (dynamic) string as JavaScript object key?

var test = "test123" var test123 ={ "key" + test: 123 } This code doesn't work. What is wrong with "key" + test ?

javascript syntax object-literal