G
G
Galdar Turin2020-08-05 23:00:43
Node.js
Galdar Turin, 2020-08-05 23:00:43

How to write a new object to an object?

Maybe someone has come across this, how many have already written a record of objects for the first time.
I write the identifier of the new object to the obj object and there are many other objects in it, but it turns out that they are overwritten in the object and as a result something like this is obtained

'0000000000': { 217:{ data: '00000000', checksum: '2400' } }

although it should be
obj = { 250:{ 1:{ data:"001", checksum :'' }, ..., 9:{ data:"001", checksum :''  } } }


for( var i in resultArr)
            {

                if( Object.keys(obj).indexOf(resultArr[i].IMEI) == -1)
                {
                    obj[resultArr[i].IMEI] = {}
                }

                if( Object.keys(obj[resultArr[i].IMEI]).indexOf(resultArr[i].id) == -1 )
                {
                    obj[resultArr[i].IMEI][resultArr[i].id] = {}
                    obj[resultArr[i].IMEI][resultArr[i].id].data = resultArr[i].data
                    obj[resultArr[i].IMEI][resultArr[i].id].checksum = resultArr[i].checksum
                }

            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question