Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-02-05
3
Medium Priority
?
142 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

618 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