Solved

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

Posted on 2015-02-05
3
119 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

791 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