?
Solved

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

Posted on 2015-02-05
3
Medium Priority
?
137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
Brian Tao earned 2000 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 43

Expert Comment

by:Rob
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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