This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jun 22, 2011, 12:47 AM
29 Posts
topic has been resolvedResolved

search an array for a string value

  • Category: Debugging
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags: array
  • Replies: 4
Hi,
 
I have what i hope is a simple one to solve. I want to go through my view and build an array of unique values.

I have managed to make the array OK, but when I search for a value using

myarray.contains("some string")

I get an error saying "Error calling method 'contains(string)' on an object of type 'Array [JavaScript Object]"
 
Any suggestions on how I can search my array for a value?

P.S. Code worked OK when I added docid's..
 
Maybe I shouldn't be using an array?
Jun 22, 2011, 4:07 AM
54 Posts
Re: search an array for a string value
Does this help?
http://stackoverflow.com/questions/237104/javascript-array-containsobj

Seems like you could (??) use the "indexOf" or the DOJO framework contains some utility functions. If not, you can always create a small util function of your own.
Jun 22, 2011, 7:36 AM
261 Posts
Re: search an array for a string value
Hi,
 
Two questions: what does your array consist of and where are you processing it?

Lets assume you want to process it server-side using SSJS.
  • If it's an array of strings you can use the @IsMember( value, array) function.
  • If it's an array of objects you'll probably have to write a function yourself.
Mark
Jun 22, 2011, 9:31 PM
47 Posts
Re: search an array for a string value
 Is this for SSJS or client javascript?
 
Assuming the former, you might want to use something other than an array, like a java.util.Vector or java.util.ArrayList. You might as well get comfortable with java.util.Vector as that is what getItemValue and replaceItemValue methods use.  If you have to have an array at some point, you can convert either of them to an array with toArray().
 
Rich 
Jun 26, 2011, 11:24 PM
29 Posts
Re: search an array for a string value
Hi everyone, thanks for the suggestions.
 
Worked out the solution, I needed to give the array a value, so I just

on my after page loads I have this

javascript:var athleteList = new Array();
sessionScope.put("athleteList", athleteList);

So I changed my code to this and it worked. I obviously needed to initialise it differently

var newList = sessionScope.get("athleteList");
newList.length=0;
 
no idea why
 
var athleteList = new Array(); didn't work by itself, hopefully may help out some others.

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal