Recursive function to get unique properties
The function is a bit repetitive, as both cases (iterating over sub array vs individual elements) check if the element is undefined and if the return array includes that value. That could potentially be abstracted to a separate function or simplified.



It appears that the following line:


var index = props[level];



Could be moved outside of the forEach function, since it doesn't depend on any of the variables defined inside the callback function.



If you know that the values to be compared will most likely be primitive values like strings or integers then Array.includes() could likely be used to replace the calls to retArray.some(). While it may not reduce the computational complexity, it would allow simplifying the code to check for existing values. Note that function isn't supported by IE and other older browsers, and is case-sensitive when comparing strings and characters1