JavaScript arrays
BlitzMax Forums/BlitzMax Programming/JavaScript arrays
| ||
Hi, I've been trying to convert some javascript to Bmax but I can't figure out what arrays are in Java? I.e. are they blitz arrays or lists, I'm a bit confused because Java arrays seem to be both!! Here is some code:var array = new Array(); var array2 = new Array(); var a = 0; array[a] = false; var length = array2.length; That's obviously just an example, but I think you know what I mean. |
| ||
Java and JavaScript are two different languages. |
| ||
Java arrays are just a container class, as is BMs Array class. How you port your code depends on what it is meant to do. In above example you surely would use arrays. |
| ||
It's JavaScript. Yeah see I thought it would be arrays too but arrays dont allow you to AddLast getLength etc. Do they? |
| ||
??? somearray.length is its length but you are right, addlast etc does not work like that, thats why slicing exists. |
| ||
JS arrays are not real arrays like in c/c++. They are array like objects. http://www.w3schools.com/jsref/jsref_obj_array.asp |
| ||
They seem very similar to Lists, but the added ability to do this, which is annoyingarray[myVariable]; |
| ||
If you need a list value at a certain index use ValueAtIndexGlobal t:TList=New TList t.addLast("ab") t.addLast("cd") Print String(t.ValueAtIndex(1)) |
| ||
Javascript arrays are NOT linked lists. In terms of use they are like normal arrays but with the feature that they can increase in size dynamically to what is required, and they can hold different types of variable. For example, [0] could be integer and [1] could be string. If you created an array of size 5, but then made [9] = something, the array would increase in size to be 10 elements long. ([5]-[8] being empty for now). This can be both very useful and annoying depending upon what you are doing, and your ideas of what is "good practice". |