array.lastIndexOf

Feb 27, 2007 at 1:35pm

array.lastIndexOf

in the following function, there is an array ‘myArray’ which is filled with data from SoftVNS. I want to call a number of functions on it – myArray.length works, but many others do not including ‘indexOf’ and ‘lastIndexOf’ as in

var index = array.lastIndexOf(searchElement[, fromIndex]);

could anyone tell me if I am missing something or is the entire JavaScript API not implemented in Max?

Thanks, Garth

// list — populates the array with the list
function myList(aList)
{
var num=0;
var listLength = 0;
var theIndex=0;
myArray = arrayfromargs(arguments);
post(“n received list ” + myArray);

post(“n the list contains :” + (arguments.length-1) + ” elements”);
post(“n itemNumber: ” + itemNumber + ” is: ” + arguments[itemNumber] + “n”);

listLength = arguments.length;

for (i=0; i

{
myArray[i] = myArray[i];

if (myArray[i] > num)
{ num = myArray[i];
theIndex = i;
}
}
post(“The largest number in the list was: ” + num + ” at index: ” + theIndex + “nn”);
}

#30484
Feb 27, 2007 at 2:15pm

#97621
Mar 1, 2007 at 9:07am

In your example I don’t see the use of lastIndexOf.

But, just in case, mind you that ‘arguments’ is -not- an array (made that mistake myself). You first need to call arrayFromArgs. Have another close look at the arrayfromargs documentation in JavascriptInMax.pdf

Greets,
Mattijs

Quote: ga.paine@uws.edu.au wrote on Tue, 27 February 2007 14:35
—————————————————-
> in the following function, there is an array ‘myArray’ which is filled with data from SoftVNS. I want to call a number of functions on it – myArray.length works, but many others do not including ‘indexOf’ and ‘lastIndexOf’ as in
>
> var index = array.lastIndexOf(searchElement[, fromIndex]);
>
> could anyone tell me if I am missing something or is the entire JavaScript API not implemented in Max?
>
> Thanks, Garth
>
>
>
> // list — populates the array with the list
> function myList(aList)
> {
> var num=0;
> var listLength = 0;
> var theIndex=0;
> myArray = arrayfromargs(arguments);
> post(“n received list ” + myArray);
>
> post(“n the list contains :” + (arguments.length-1) + ” elements”);
> post(“n itemNumber: ” + itemNumber + ” is: ” + arguments[itemNumber] + “n”);
>
> listLength = arguments.length;
>
> for (i=0; i

> {
> myArray[i] = myArray[i];
>
> if (myArray[i] > num)
> { num = myArray[i];
> theIndex = i;
> }
> }
> post(“The largest number in the list was: ” + num + ” at index: ” + theIndex + “nn”);
> }
>
—————————————————-

#97622

You must be logged in to reply to this topic.