Strange behavior in creating dictionaries

Hello everyone,
please have a quick look at following code. I think I do not have to explain it.



let user_data = {
lotNumber : 0 ,
name : “Meyer” ,
surname : “Hans” ,
street : “Straße” ,
houseNumber : “1” ,
postalCode : 11111 ,
city : “Stadt”
};

wixData . query ( “database_lots” )
. count ()
. then (( num ) => {
let start_id = num ; //= 52

    **for**  ( let  i  =  0 ;  i  <  2 ;  i ++) { 
        user_data [ "lotNumber" ] =  start_id ; 
        console . log ( start_id  +  " : "  +  user_data [ "lotNumber" ]); 
        console . log ( user_data ); 
        start_id ++; 
    } 

}) 
. catch (( error ) => { 
    let  errorMsg  =  error . message ; 
    let  code  =  error . code ; 
    console . log ( errorMsg ); 
}); 


When I run this code snippet it will prompt the following:


Seems to look exactly like what I want. But wait… when I am opening the dictionary to look into it the variable “lotNumber” suddenly has a different value.

Maybe I am blinded of my own code but I do not get it.

Can you help?

Perhaps I am missing something but I don’t see any place in this code where you are updating and inserting new data into the database collection. So the query will always return whatever is in the line item.

If you want to make a change to data in the collection, take a look at these docs
Wix Data Update
or
Wix Data Insert - if you are wanting to add a new row of data