No internet connection
  1. Home
  2. How to

Trouble using find() method on memoryLocationsFetch()

By samuel henriques @samuel_henriques
    2022-12-09 15:23:41.502Z

    Hello everyone,
    came across an issue I couldn't figure out the answer for.

    Was looking for the first element with a condition on an array of objects.

    FIlter works:

    let memLocFilter = sf.proTools.memoryLocationsFetch().collection['List'].filter(m => m.name === "marker 2")
    log(memLocFilter[0]) // I get the first from an array of elements
    
    

    But If I try find() I get Type error:

    let memLocFind = sf.proTools.memoryLocationsFetch().collection['List'].find(m => m.name === "marker 2")
    log(memLocFind)
    // TypeError: No public methods with the specified arguments were found: 'Find'
    

    What am I missing?

    • 4 replies
    1. Brenden @nednednerb
        2022-12-09 20:57:29.822Z

        I saw something like this happen in the Weekly Hangout when Kitch was in control of the keypresses...

        Does it have something to do, maybe, with the following?

        When I take the line,

        let memLocFind = sf.proTools.memoryLocationsFetch().collection['List']
        log(memLocFind)
        

        In this example, the first line is truncated as above, and what it returns is an array of objects.

        If I remember correctly, Kitch said that the method might be failing because it doesn't divide the array into objects before trying to find its contents and so cannot return the right value.

        I forget the workaround that was supplied :-)

        1. samuel henriques @samuel_henriques
            2022-12-09 21:42:37.542Z

            Good idea,
            this works, thank you for the tip.

            sf.proTools.memoryLocationsFetch().collection['List'].slice().find(.....)
            
            1. Kitch Membery @Kitch2022-12-10 00:00:13.011Z

              Hi Samuel,

              I just refactored a script for getting memory locations last night, see this post;

              I have a hunch that the sf.proTools.memoryLocationsFetch() may not be fully implemented, but I can't be sure.

              Rock on!

              1. Yea I think this action always ended up in the wrong location. It would be best not to use sf.proTools.memoryLocationsFetch directly and instead read straight from the table if possible.