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

80
Views
String to array object in javascript

I have a string like this:

var x = "[{"id": "40", "text": "Budi "}, {"id": "47", "text": "Staff 01"}]"

I expect to loop until end and read the id and text one by one, how to do this in javascript?

I have tried below:

var myArr = JSON.parse(x);
for (var i in myArr) {
     alert(myArr[i]);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your JavaScript is invalid. Make sure to wrap it in single quotes.

var x = '[{"id": "40", "text": "Budi "}, {"id": "47", "text": "Staff 01"}]'
var myArr = JSON.parse(x);
for (var i in myArr) {
     console.log("id: " + myArr[i].id);
     console.log("text: " + myArr[i].text);
}

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!