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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:07:25+00:00 2026-06-11T09:07:25+00:00

I want to do the following: // an object var object = { one:

  • 0

I want to do the following:

// an object
var object = {
    one: null,
    two: null,
    three: null
};

// an array
var array = ['this is one', 'this is two', 'this is three'];

I now want to merge them both together so I get;

var merged = {
    one: 'this is one',
    two: 'this is two',
    three: 'this is three'
};

I don’t want to use any 3rd library just pure javascript (ECMA5).

So what is the trick?

Regards,
bodo

  • 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-11T09:07:26+00:00Added an answer on June 11, 2026 at 9:07 am

    Try this:

    // an object 
    var object = {
        one: null,
        two: null,
        three: null
    };
    
    // an array 
    var array = ['this is one', 'this is two', 'this is three'];
    
    function merge(arraysrc, array2dest) {
    
        var x, i = 0;
    
        var merged = [];
    
        for (x in array2dest) {
            var obj = {};
            obj[x] = arraysrc[i++];
            merged.push(obj);
        }
        return merged;
    }
    
    var a = merge(array, object);
    
    alert(JSON.stringify(a));​
    

    http://jsfiddle.net/6mQYN/

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

Sidebar

Related Questions

Hi I have the following object: Hashtable<Object, Double> and I want to find the
In C# if I have the following object: IEnumerable<Product> products; and if I want
I have date in sting object in following format. dd/mm/yyyy I want to change
I want to find out the following: given a date ( datetime object), what
I want to reset an object. Can I do it in the following way?
Is it possible to do the following? List<Object o, Object p> listWithTwoObjects; I want
I have the following structure: var $html = $(<div id='a'><div id='b'><div id='c'></div></div></div>); I want
I want to override some style provided in struts/xhtml/style.css. One of them is label
I want to create a helper object that will work the following way: It
I want to test the following two (unrelated) methods and achieve full branch and

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.