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

  • SEARCH
  • Home
  • 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 7711881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:29:19+00:00 2026-06-01T01:29:19+00:00

I’m not sure if this is even what you call it, but basically, I

  • 0

I’m not sure if this is even what you call it, but basically, I am grabbing a list of cities that is stored in one key in local storage. I am splitting them by comma, and then dynamically checking the checkboxes with the corresponding values for the id. Now I want to have any number of cities in there so I don’t want to check the boxes individually like [0], [1] etc but is there there like a unlimited way to do this or something. Sorry if this isn’t clear..Ill post my code below, My code below is checking the boxes from keys 0-5, I want to be able to do 0 – unlimited , so to speak. Any help is appreciated.

<script type="text/javascript">
            var refreshId = setInterval(function()
                                        {
            var citySplit = localStorage.getItem("city2");

            var myResult = citySplit.split(",");

            $("#"+myResult[0]+"").prop("checked", true);
            $("#"+myResult[1]+"").prop("checked", true);
            $("#"+myResult[2]+"").prop("checked", true);
            $("#"+myResult[3]+"").prop("checked", true);
            $("#"+myResult[4]+"").prop("checked", true);
            $("#"+myResult[5]+"").prop("checked", true);
             }, 6500);

            </script>
  • 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-01T01:29:21+00:00Added an answer on June 1, 2026 at 1:29 am

    Many ways to do this:

    NOTE: All of these examples are untested.


    Simple while-loop – 0, 1, 2, 3, 4

    var i = 0,
        len = myResult.length;
    
    while ( i < len ) {
        $( "#" + myResult[i] ).prop("checked", true);
        i++;
    }
    

    Simple for-loop – 0, 1, 2, 3, 4

    for ( var i = 0, len = myResult.length; i < len; i++ ) {
        $( "#" + myResult[i] ).prop("checked", true);
    }
    

    jQuery.each method with callback using this

    $.each(myResult, function() {
        $( "#" + this ).prop("checked", true);
    }
    

    or
    jQuery.each method with callback using arguments[1] (value)

    $.each(myResult, function(key, value) {
        $( "#" + value ).prop("checked", true);
    }
    

    while-loop from behind 4, 3, 2, 1, 0

    var len = myResult.length
    
    while( len-- ) {
        $( "#" + myResult[len] ).prop("checked", true);
    }
    

    for-loop from behind 4, 3, 2, 1, 0

    for( var i = myResult.length; i > 0; i-- )
        $( "#" + myResult[i-1] ).prop("checked", true);
    

    while-loop popping array This destroys the array from behind 4, 3, 2, 1, 0

    while( myResult.length ) {
        $( "#" + myResult.pop() ).prop("checked", true);
    }
    

    or
    while-loop shifting array This destroys the array from the start 0, 1, 2, 3, 4

    while( myResult.length ) {
        $( "#" + myResult.shift() ).prop("checked", true);
    }
    

    ???


    $.map(myResult, function(value) {
        return "#" + value;
    }).each(function() {
        $(this).prop("checked", true);
    };
    

    $.map(myResult, function( value ) {
        return $("#" + value);
    }).prop("checked", true);
    

    As you can see there is many ways to dealing with arrays.

    For simple thing I will recommend you to use one of the two first methods.

    The jQuery.each method is very nice because you get a the key and value of the array in a local scope. (key = 0, 1, 2, 3, 4, …) (value = what ever myResult[key] is).

    The two where we destroy the array is also very nice. But I will not recommend you not to use these before you understand more simple methods. As situation i can think of using this method is if you have to load a lot of files or initialize a lot of functions in a specific order:

    var func1 = function() {
            alert("func1");
        },
        func2 = function() {
            alert("func2");
        },
        func3 = function() {
            alert("func3");
        },
        queue = [func1, func2, func3];
    
    while( queue.length ) {
        (queue.shift())(); 
        // or
        //(queue.pop())();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,

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.