Leetcode three sum in Javascript
Current code
Before discussing the algorithm I want to discuss the current code.
The code currently uses functional approaches - like forEach() methods. This is great for readability but because a function is called for every iteration of each loop, performance can be worse than a regular for loop - e.g.  each function adds to the call stack.
The current code also uses hasOwnProperty. For a plain object the in operator could be used since it doesn't matter if the property would be inherited or not.
The last block is this:

const finalErr = []


Object.keys(triplet_memory).forEach(el =&gt; {
    const elements = el.split('/').map((element) =&gt; {
        return parseInt(element)
    })
    finalErr.push(elements)
})
return finalErr

It is interesting that there is a .map() call nested inside a .forEach() loop that pushes elements into an array - the latter is the essence of a .map() call. So the .forEach() could be simplified to a .map() call:
return Object.keys(triplet_memory).map(el =&gt; {
    return el.split('/').map((element) =&gt; {
        return parseInt(element)
    })
})

This way there is no need to manually create finalErr, push elements into it and then return it at the end.
Different Algorithm
There are multiple posts about this problem on code review (and SO as well). This buzzfeed article explains multiple approaches including The hash map solution and the two pointer trick, the latter of those two is a great solution.

Two pointer trick
The ‘two pointer trick’ gives a really nice solution to 3sum that doesn’t require any extra data structures. It runs really quickly and some interviewers ‘expect’ this solution (which might be somewhat unfair, but now that you’re seeing it, it’s to your advantage).
For the two pointer solution, the array must first be sorted, then we can use the sorted structure to cut down the number of comparisons we do. The idea is shown in this picture:



vector&lt;vector&lt;int&gt;&gt; threeSum(vector&lt;int&gt;&amp; nums) {
 vector&lt;vector&lt;int&gt;&gt; output;
 sort(nums.begin(), nums.end());
 for (int i = 0; i &lt; nums.size(); ++i) {
   // Never let i refer to the same value twice to avoid duplicates.
   if (i != 0 &amp;&amp; nums[i] == nums[i - 1]) continue;
   int j = i + 1;
   int k = nums.size() - 1;
   while (j &lt; k) {
     if (nums[i] + nums[j] + nums[k] == 0) {
       output.push_back({nums[i], nums[j], nums[k]});
       ++j;
       // Never let j refer to the same value twice (in an output) to avoid duplicates
       while (j &lt; k &amp;&amp; nums[j] == nums[j-1]) ++j;
     } else if (nums[i] + nums[j] + nums[k] &lt; 0) {
       ++j;
     } else {
       --k;
     }
   }
 }
 return output;


1