can array methods e.g. push, pop etc. be used with an array of objects?
Announcement
Collapse
No announcement yet.
Array Methods
Collapse
X
-
Hello futurenets,
Please post a code example of what you're trying to do.Jason K.
Project Manager
eSignal - an Interactive Data company
EFS KnowledgeBase
JavaScript for EFS Video Series
EFS Beginner Tutorial Series
EFS Glossary
Custom EFS Development Policy
New User Orientation
-
creating an array of objects ....
var myArray = new Array();
for (x=0; x<20; x++) {
//create the object
var tmp = new Object;
//fill the object with data
tmp.priceHigh = high(-x);
tmp.priceLow = low(-x);
tmp.priceChange = (close(-x)-close(-(x+1)))/close(-(x+1));
//assign it to the array element
myArray[x] = tmp;
}
is it possible to re-dimension myArray? or use any of the standard array methods push, pop etc.Paul Williams
Strategy & Applications
www.futurenets.co.uk
Comment
-
Hello Futurenets,
Yes, this will work and you can use the pop, push, shift and unshift methods to manipulate the size of the array. Here's the code snippet I just tested.
PHP Code:var myArray = new Array();
function main() {
if (getCurrentBarIndex() != -1) return;
for (x=0; x<20; x++) {
//create the object
var tmp = new Object;
//fill the object with data
tmp.priceHigh = high(-x);
tmp.priceLow = low(-x);
tmp.priceChange = (close(-x)-close(-(x+1)))/close(-(x+1));
//assign it to the array element
myArray[x] = tmp;
}
debugPrintln(myArray[0].priceHigh);
}
Jason K.
Project Manager
eSignal - an Interactive Data company
EFS KnowledgeBase
JavaScript for EFS Video Series
EFS Beginner Tutorial Series
EFS Glossary
Custom EFS Development Policy
New User Orientation
Comment
Comment