Solved

How to create an array with custom properties in javascript or jquery

Posted on 2015-02-05
3
109 Views
Last Modified: 2015-03-02
How do I create something like this in javascript or jquery:

myarray(#).title
myarray(#).year
myarray(#).country

For example, data:

myarray(1).title = "canada"
myarray(2).title = "america"
myarray(1).year = "1999"

etc.

Thanks.
0
Comment
Question by:intoxicated_curveball
3 Comments
 
LVL 9

Accepted Solution

by:
Brian Tao earned 500 total points
Comment Utility
Javascript uses [] as its array indexing operator.  The expected variable is an array of object, which can be done using:
var myarray=[{'title':'canada','year':'1999'},{'title':'america'}];

// to show the result
// alert(myarray[0].title + ', ' + myarray[0].year + ', ' + myarray[1].title);

Open in new window

0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
Please see my article on objects and arrays.  http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_13138-Javascript-is-just-an-Object.html

An array and object are VERY closely linked
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now