Within my code, I have a nested loop structure consisting of a for of
with a for in
loop inside it. This setup retrieves information from a Neo4J database. By utilizing the Object.assign
method, I am able to transfer a property from the fetched object into a new object. As far as I understand, this process ensures immutability.
In the subsequent step, I aim to incorporate the newly generated result object into an array for each returned result.
To achieve this, one option is to initialize an empty array outside the loop and then utilize Array.concat
to create a fresh array during each iteration. However, I acknowledge that neither of these approaches truly maintain immutability since they involve either pushing elements into an array or overwriting a variable.
I am left wondering if there exists a method to culminate in an immutable results array containing all objects?
let results = []
for (const row of argsArray) {
for (const key in row) {
const neo4jPropInUse = await neo4j.session(null, cypher.ngp(key, row[key]))
if (neo4jPropInUse.length !== 0) {
console.log('IN USE DETECTED')
const thingResult = Object.assign({}, {
[thingSerialNumber]: neo4jPropInUse[0].get(`RESULT`).properties[thingSerialNumber],
key: key
})
results = results.concat([thingResult])
}
}
}