Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
How to generate random unique static id in javascript

I am prototyping a project that requires a unique id for each functions. here is an example.

function Example(name, uuid) {
    ...
}

function start() {
    Example("Jeeva", 1)
    if (...) {
        Example("Peter", 2)
    }
    Example("June", 3)
}

As you can see the start function may called multiple times. but I want the id to be same. the id doesn't have to be a number it could be anything but has to unique to that function call.

I tried to store the ids in a list outside the start function and adding the id on first call and shifting them on other calls. But the issues is inside the if statement the function might not be executed. so after the first call if the condition changes then Example function will be called and shifting the id will return fails.

Can anyone point me in the right direction or is it impossible in this case?

Edit

OK, let me tell you why do I want this functionality. Simply put I am trying jetpack compose. If you don't know how jetpack compose works. It's a declarative UI framework. It updates (recompose) it's UI on state changes.

I am not doing this project for production, just to learn (out of curiosity).

here is an example that I am testing right now.

import { Compose } from "../src/core/Compose"
import { Text } from "../src/composable/Text"

const App = scope => {
    let text = scope.stateOf("hello", 1)

    Text({ 
        text: text.value
    }, scope, 1)

    if (text.value === "hello, world") {
        Text({ text: "Hi" }, scope, 2)
    }

    if (text.value == "hello") {
        setTimeout(() => text.value = "hello, world" , 2000)
    }
}

new Compose("#app").mount(App)

As you can see I am passing unique numbers at the end of each composables and state. this allows me to find them on recomposition.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!