Solved

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

Posted on 2015-02-05
3
113 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
ID: 40592633
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
ID: 40593311
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

912 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

24 Experts available now in Live!

Get 1:1 Help Now