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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:28:58+00:00 2026-06-05T04:28:58+00:00

I have an array with keys and values which elements i want to push

  • 0

I have an array with keys and values which elements i want to push into 2 different arrays (key into one and value into another)

here is the code i have used:

// the array i want to split
var defaultc = {
    'a':'r019',
    'b':'r027',
    'c':'r027',
    'd':'r027',
    'e':'r047'
};
// the array i want to add to
var step_layer = []; // keys to this
var step_colour = {}; // values to this


$('#reset').click(function() {
    $.each(defaultc, function(layer, colour) {

        // both these functions are working properly
        apply_changes(layer, colour);
        sumary(layer, colour);
    });

    // this part is not
    for (var layer in defaultc) {
        if (!defaultc.hasOwnProperty(layer)) {
        step_layer.push(layer);
        step_colour[layer].push(colour);
    }}
    return false;
});
  • 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-05T04:29:03+00:00Added an answer on June 5, 2026 at 4:29 am

    You have an Object, not an Array. Its quite simple:

    var step_layer = Object.keys(defaultc); // array of property names
    var step_colour = Object.values(defaultc); // arrray of property values
    

    But as .values is a non-standard method, .keys only available on modern browsers and the iteration order of object properties is not fix, you should use a single loop over the object:

    var step_layer = []; // array of property names
    var step_colour = []; // arrray of property values
    for (var layer in defaultc) {
        step_layer.push(layer);
        step_colour.push(defaultc[layer]);
    }
    

    And that’s where your code differs. First, you start with a var step_colour = {};. This is a object again, to be used for a key-value-map. So, it even would be possible to access a property of it with step_colour[layer], but this is still undefined. You seem to assume that it would be an array, using .push on it – that will throw an error (look into your debugging console). Im not sure what you want to achieve with that. Creating an array, cloning the defaultc variable?

    Another problem is if (!defaultc.hasOwnProperty(layer)). First, your defaultc is a plain object and does not inherit any enumerable properties, so just leave that condition away. Second, as all layers you loop over are own properties of defaultc, the block will never get executed.

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

Sidebar

Related Questions

I have a multidimensional array of arrays (source below), where my keys and values
I have a PHP 2D array, many keys, each with one value, I need
I have two arrays the first one has this structure Parameter Keys array array
I have two arrays containing different keys and values. However, some keys store strings
Possible Duplicate: Dynamic array keys I have an array $Values which is set up
I have two arrays values and keys both of the same length. I want
I have a HashMap which I want to convert into a array. Which the
I have an array which is dynamic, and key and values are displaying in
I have an array which contains many keys/values that are generated dynamically, so I
I have an array that has keys and values. For eg: Array ( [name]

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.