Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:10:26+00:00 2026-06-04T16:10:26+00:00

I suspect this is an easy problem, but I am a bit new to

  • 0

I suspect this is an easy problem, but I am a bit new to js and can’t find the solution.

Basically, when I pass a JSON string to a function and then attempt to iterate through the passed variable, it treats it like a literal string rather than an array.

With this function:

function build_codes_long(codes) {
   var codes_long_text = "";
   for(var i =0;i < codes.length-1;i++) {
      var code = codes[i];
      codes_long_text += "<p>" + code['id'] + " = " + code['del'] + "</p>";
   }
return codes_long_text; 
}

When I pass a JSON string to it like:

[{"id":"1","del":"0","clip":"1"},{"id":"2","del":"0","clip":"1"}]

It evaluates each character in the string, rather than each item in the array. So it loops 65 times instead of 2, returning something like:

undefined = undefined

I understand the problem with the returned values; it’s the treating the array like a literal string I don’t understand. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:10:27+00:00Added an answer on June 4, 2026 at 4:10 pm

    It’s because you’re not looping through an object; you’re looping through a string and getting each letter as a result.

    You need to convert the JSON string to an object first:

    var myObject = JSON.parse(myJsonString);
    var codesLongText = build_codes_long(myObject);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect there is an easy answer for this question but I can't find
I suspect there's probably an easy answer to this I'm just not seeing, but
I suspect the solution to my problem to be very easy with LINQ to
I suspect this question has been asked before, but it's not easy to Google
I suspect this applies to general ASP.Net too but I am not sure. If
I suspect this is impossible, but thought I'd ask. Say I have a class
I am new to both DBs and Rails (using 3.2), and I suspect this
Now this is probably really easy but being the tool that I am, I'm
it seems to me that this is kind of a very easy question, but
I'm using the SHA1Managed class in my code, but this causes a problem when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.