/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@TcobbAug 28.2014 — 
  • 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?
  • Copy linkTweet thisAlerts:
    @rootAug 28.2014 — indexOf() certainly does work, my MSIE browser is version 8, you must be doing something wrong.

    [CODE]var str="CSMTestPWXListinerService,CSMTestPWXListinerService_ManualyAdded";
    console.log(str.indexOf(","));[/CODE]

    returns LOG:25 in my IE8 Console Log
    Copy linkTweet thisAlerts:
    @helixpointauthorAug 28.2014 — It could have quite a few dimensions
    Copy linkTweet thisAlerts:
    @TcobbAug 28.2014 — 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.

    [CODE]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;

    do{
    flag = false;
    list = holder;
    holder = [];

    len = list.length;
    while(len--){
    if(list[len]['mark']){ //if its an array
    holder = holder.concat(list[len]);
    flag = true;
    continue;
    }
    if(list[len] === sought){ //the value does occur in the array
    return true;
    }
    }
    } while(flag);
    return false;
    }[/CODE]
    ×

    Success!

    Help @helixpoint spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.21,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...