I am trying to create a JSON object, with a random string as the name, just like how Firebase does it.
Goal: replace child name with random string.
For example:
"Users" : {
    "mGKgNDOw0qd77m6tmdDh76zOQOm2" : {
      "email" : "someuser@gmail.com",
      "firstName" : "some",
      "lastName" : "user",
      "username" : "someuser"
    },
    "vyMiCS7olNPh9bCXoKWqcIFNWVy2" : {
      "email" : "someuser2@gmail.com",
      "firstName" : "some",
      "lastName" : "user2",
      "username" : "someuser2"
    }
}
This is what I got so far, I manage to get my head around with a string randomise function.
randomString(length) {
    return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
}
And I would like to push my data into the object with random string as the name.
I tried string interpolation but it does not work.
var expensesObject = {
  uid: {
    amount: spentAmount,
    category: selectedCategory,
    date: formattedDate,
    time: formattedTime,
    note: note
  }
}
 
     
     
     
     
     
    