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 8969547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:36:28+00:00 2026-06-15T17:36:28+00:00

If I have a list like this: var a= [[‘1′[0]],[‘2′[0]],[‘3′[0]],[‘4′[0]]]; and if condition that

  • 0

If I have a list like this:

var a=  [['1'[0]],['2'[0]],['3'[0]],['4'[0]]];

and if condition that should another variable be equal to either ‘1’,’2′,’3′,’4′ then to increment the values of their list eg:

for(var i=0; i<a; i++{
 if(a[i] == z) {
   a[i] += z;
    }
}

I know the above code will not work, but how could I get each ‘inner’ element to incerment?

I’m a javascript novice, so please excuse any errors in the code.

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-15T17:36:29+00:00Added an answer on June 15, 2026 at 5:36 pm

    Those innermost arrays are at index [1] of the first set of inner arrays, assuming your array’s actual format is:

    // Note the commas between the inner elements which you don't have above.
    var a = [['1',[0]],['2',[0]],['3',[0]],['4',[0]]];
    

    So you’re nearly there, you need to access a[i][1][0] and incrememnt it ++ rather than += z.

    Examples:

    console.log(a[1][1][0]);
    // 0  (at element '2')
    
    // z is the string value you are searching for...
    for(var i=0; i < a.length; i++) {
      // Match the z search at a[i][0]
      // because a[i] is the current outer array and [0] is its first element
      if(a[i][0] == z) {
        // Increment the inner array value which is index [i][1][0]
        // Because the 1-element inner array is at [i][1] and its first element is [0]
        a[i][1][0]++;
      }
    }
    

    So for z = '2':

    // Flattened for readability:
    a.toString();
    // "1,0,2,1,3,0,4,0"
    //-------^^^
    

    Then z = '4':

    // This time the '4' element gets incremented
    a.toString();
    // "1,0,2,1,3,0,4,1"
    //-------^^^-----^^^
    

    Here’s a demo on jsfiddle…

    Update: This is where the updated value resides:

    Console example

    The Array[1] 0: 1 is the incremented value for z == '4'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some LINQ code that generates a list of strings, like this: var
I have an object structure that looks like this: var Results = new List<ResultObj>()
I have a list that is built like this: <ul id=ajaxList class=ajaxListUL> and then,
I have a list of objects MyObject and that looks like this: var Obj1
So i have a List of strings that looks like this: var ls=new List<string>()
I have a pretty simple structure that looks something like this: var list =
I have an ordered list like this: var list = new List<String>(){aaa,aab,aac,baa,bab,bac}; I want
I have a list of hierarchical data like this: var list = new List<Data>(){some
Suppose I have a list of strings, like this: var candidates = new List<String>
Say I have a collection of object arrays of equal dimension, like this: var

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.