How to Assign a value to a empty string inside function

Hi, I was unable to assign value to the firstName as shown below , Can anyone suggest me the proper way to assign the value to a empty string
let getDetails = (id) => {
let firstName = “”
state->Array.map(c => {
switch (c.id == id) {
| true => let firstName = (c.name)
| false=> ()
}
})->ignore
firstName
}

You can use a ref, e.g.

let firstName = ref(””)
firstName := ”Kim” // or firstName.contents = ”Kim”

See Mutation | ReScript Language Manual

It highly depends on your use case. Without any context, I would write something like this:

let getDetails = id => {
  switch state->Array.find(c => c.id === id) {
    | Some(user) => user.name
    | None => ""
  }
}

or

let getDetails = id => {
  state->Array.find(c => c.id === id)->Option.map(user => user.name)
}