0

i get large data array of object about 3mb and iterate it but the issue is that is giving me memory error.

below is my code

  stocks.map((value)=>{
        stocksCrudService.updateDocumentByKeySet({
          stocks_id: value.id
        }, {
          stocks_id: value.id,
          exchange: value.exchange,
          name: value.name,
          symbol: value.symbol,
          tradable: value.tradable,
          status: value.status
        }).then((response)=>{
            console.log(response)
        }).catch((err)=>{
            console.log(err)
        })

any best solution?

  • 1
    Does this answer your question? [Best way to iterate over an array without blocking the UI](https://stackoverflow.com/questions/10344498/best-way-to-iterate-over-an-array-without-blocking-the-ui) – empiric Oct 05 '21 at 14:12
  • Maybe this can help you: https://stackoverflow.com/questions/50774384/asynchronously-iterate-through-large-array-of-objects-using-js-jquery?noredirect=1&lq=1 – coding_noob Oct 05 '21 at 14:12
  • I don't have a solution for the memory problem, but it looks a bit strange that you iterate `stocks` with `map()`, but nothing is returned. You should probably use `forEach()` instead of `map()`. But I support @empiric - you should probably use [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers). The web worker can do the fetch request. – chrwahl Oct 05 '21 at 14:46

0 Answers0