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

201
Views
Is there a way to convert a string to a proper array, not an array of strings or an array of characters?

I have this string “[{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}]" and I need to convert into a list [{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}] in JavaScript, is there a way to do that??

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use the eval() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!)

Please be aware, that eval() shouldnt be used generally as you can read in the article above.

Example:

const array = eval('[{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}]');

Edit: I would suggest to modify you string to fit the JSON-Standard. To achieve this, you would have to put the keys of your objects in quotation marks like this:

let yourString =  '[{"value": 1400, "value1": 50, "value2": 48}, {"value": 1500, "value1": 20, "value2": 88}]';
const array = JSON.parse(`${yourString}`);

This will work ^^

about 4 years ago · Juan Pablo Isaza 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!