gandalf98 Posted September 22, 2009 Share Posted September 22, 2009 Hello all, Need help with finding the index of an array element. I've created an array and called it CpnArray. When I attempt the following: CpnArray.indexOf(CpnVrsn) FusionPro tells me that CpnArray.indexOf is not a function. I don't want to set up an external file and look up the record... That is going to eat up too much memory and time for this job. Can I not look up the index of an element in an array? That seems way to simple of a Javascript concept to not be implemented. Please help! Link to comment Share on other sites More sharing options...
tobarstep Posted September 23, 2009 Share Posted September 23, 2009 Hello all, Need help with finding the index of an array element. I've created an array and called it CpnArray. When I attempt the following: CpnArray.indexOf(CpnVrsn) FusionPro tells me that CpnArray.indexOf is not a function. I don't want to set up an external file and look up the record... That is going to eat up too much memory and time for this job. Can I not look up the index of an element in an array? That seems way to simple of a Javascript concept to not be implemented. Please help! indexOf is a method of the String object and returns the starting position of a search string within another string. Arrays are not really searchable in that respect. What are you trying to accomplish with this array? Link to comment Share on other sites More sharing options...
gandalf98 Posted September 23, 2009 Author Share Posted September 23, 2009 I see. I was attempting to use an array of Letters that correspond to page numbers in a PDF file for variable coupons: var CpnArray = [ "A", "B", "C", "D", etc. ]; when my data file came as version B, I wanted to look up the index of letter B, which would tell me to place page 2 of my coupon file. if I were to declare the variable as a string ("ABCDEFG"), I then could use indexOf? Thanks for your help... I only know enough to be dangerous. Link to comment Share on other sites More sharing options...
tobarstep Posted September 23, 2009 Share Posted September 23, 2009 A simple string could work quite well for that then. var myTest = "ABCDE"; return myTest.indexOf("B")+1; You'll need the +1 at the end because everything is 0 based. Link to comment Share on other sites More sharing options...
gandalf98 Posted September 23, 2009 Author Share Posted September 23, 2009 Already made the switch and thanks for the reminder on the "0" basis of javascript. Works great! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.