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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:07:30+00:00 2026-06-05T19:07:30+00:00

I have an object that looks like this { AF : { name :

  • 0

I have an object that looks like this

{
 "AF" : {
   "name" : "Afghanistan"
 },
 "AL" : {
   "name" : "Albania"
 }
}

It has objects for all countries.

What I would like to do is copy the objects from certain ISO’s and add them to the top of the object (without removing the original).

What I started to do is this:

var filtered = _.collect(data, function(item, key){

    if($.inArray(item.iso, ['US','CA']) !== -1) {
            return item;
    }
});

This gives me an array, with the objects. But, how would I add these to the original object?

Thank you!

  • 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-05T19:07:34+00:00Added an answer on June 5, 2026 at 7:07 pm

    As @mu-is-too-short said, JS objects have no mandatory ordering of their properties.

    Also, your objects’ properties don’t have an iso property, which you’re depending upon.
    Please edit your question once you’ve seen that 🙂

    If your code is depending on that, you’re going the wrong way. As he suggests, you should use an array instead, but you can keep the objects inside of it. I’ll suppose you start with a structure of the object literal shown first in your question. With this snippet, you’ll be creating an array with the default order, and then adding the filtered objects to the head of that array:

    var data = {
      "AF" : {
        "name" : "Afghanistan"
      },
      "AL" : {
        "name" : "Albania"
      }
    };
    
    var countries = _.collect(data, _.identity);
    
    var repeated = [];
    _.forEach(countries, function(country) {
      if (repeatsAtTheTop(country)) {
        // Added in reverse order so it preserves the  
        // original once unshifted into the original array
        repeated.unshift(country);
      }
    });
    
    _.forEach(repeated, function(item, index) { countries.unshift(item) });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;
I have a data object that looks like this: { 'node-16': { 'tags': ['cuda'],
I have an object hierarchy that looks something like this: public class Book {
I have an object that looks like this when outputted via a print_r Array
Suppose I have a json object that looks like: { id: 1, name: john
I have a message definition file that looks like this struct1 { field=name type=string
I have a filter that looks like this: <filter> <filter-name>TestFilter</filter-name> <filter-class>org.TestFilter</filter-class> <init-param> <param-name>timeout</param-name> <param-value>30</param-value>
I have an object that looks something like this: public class Student { public
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
I have two repeaters that looks like this : Arrange By: Name | Age

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.