Results 1 to 5 of 5

Thread: How to find values in array

  1. #1
    Join Date
    Jan 2014

    How to find values in array

    They use IE 8 here, so I can't use indexOf. I need to seach for a value in a multidimential array. How can I do this

  2. #2
    Join Date
    Mar 2009
    1. Is the search limited to 2D arrays or should it work for more intricate arrays of whatever number of Dimensions?

    2. Do you want the results to list all matches in the array or just a match?

    3. If just a match, does the order in which it occurs in the array matter?

  3. #3
    Join Date
    Mar 2007
    indexOf() certainly does work, my MSIE browser is version 8, you must be doing something wrong.

    var str="CSMTestPWXListinerService,CSMTestPWXListinerService_ManualyAdded";
    returns LOG:25 in my IE8 Console Log
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Jan 2014
    It could have quite a few dimensions

  5. #5
    Join Date
    Mar 2009
    You haven't really specified what this is supposed to do other than the fact it can be an N-D array. This may not be what you want, but here it is. The function returns true if the requested is present in the array and false if it isn't. The number of dimensions in the array or their symmetry is immaterial.

    function isThere(arr, sought){
        var len, list, holder, flag;
        if(!Array['mark']){  //we have to be able to ID arrays from object-objects
    	Array.prototype.mark = true;
        holder = arr;
    	flag = false;
    	list = holder;
    	holder = [];
    	len = list.length;
    	    if(list[len]['mark']){  //if its an array
    		holder = holder.concat(list[len]); 
    		flag = true;
    	    if(list[len] === sought){  //the value does occur in the array
    		return true;  
        } while(flag);
        return false;
    Last edited by Tcobb; 08-28-2014 at 11:36 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles