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

279
Views
How to change object key value number to string value

I am working on a project; the object has a dynamic key and a dynamic value. I will find which number the keys are holding, and change the number to string value, assuming the object list is too big to check each individually- more than 30 key values

const obj =  {
    one: 'jkej',
    two: 123,
    three: 'abc'
  }

Required output is

const obj =  {
    one: 'jkej',
    two: '123',
    three: 'abc'
  }

I want to change the what are the keys holding, and change the number value to string.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can loop the keys of the object and convert the values to string

Object.keys(obj).forEach((k) => {
  obj[k] = obj[k].toString()
})
about 4 years ago · Santiago Trujillo Report

0

You can do something like this

const obj = {
  one: 'jkej',
  two: 123,
  three: 'abc'
}

const convertToString = (object) =>
  Object.fromEntries(
    Object.entries(object)
    .map(([k, v]) => [k, v + ''])
  )


console.log(convertToString(obj))

about 4 years ago · Santiago Trujillo Report

0

You can iterate through the object and cast everything into a string using toString():

for (let [key, value] of Object.entries(myObject)) {
    value = value.toString()
}
about 4 years ago · Santiago Trujillo Report
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!