2

Hi say i have an object as below

{ID:'1',Name:'Some name',Notes:'NOTES'} 

and another object as

{junk:'lll'}

I need the output as

{ ID: '1', Name: 'Some name', Notes: 'NOTES', junk: 'lll' }

Below is the code that i tried

var objIssues = [
{ID:'1',Name:'Some name',Notes:'NOTES'}

];

objIssues[objIssues.length] = {junk:'lll'};

console.log(objIssues)

The out put that i got is

[ { ID: '1', Name: 'Some name', Notes: 'NOTES' },
{ junk: 'lll' } ]

I'm stuck here any help regarding this will be much helpful.

2
  • Are you using jQuery? You can use $.extend(jsonIssues, {junk:'111'}); and jsonIssues will contain you other object. Commented Feb 11, 2014 at 12:51
  • 1
    JSON is a data serialization format and your question is not related to it. I've edited and re-tagged accordingly. Commented Feb 11, 2014 at 12:54

4 Answers 4

2

use Jquery.Extend method

$.extend( object1, object2 );
Sign up to request clarification or add additional context in comments.

Comments

0

You can do like this:

var data1 = {ID:'1', Name:'Some name', Notes:'NOTES'};
var data2 = {junk: 'lll'};
var datakeys = keys(data2);
var i;

for (i =0; i < datakeys.length; i++) {
    var k = datakeys[i];
    data1[k] = data2[k];
}

console.log(data1);

Comments

0
 var data1 = {ID:'1',Name:'Some name',Notes:'NOTES'} ;
 var data2 = {junk:'lll'}, key;
 for (key in data2) {
   if (data2.hasOwnProperty(key)) data1[key] = data2[key] 
 }

Comments

0

Try this,. hope this will work for you

 var data1="{ID:'1',Name:'Some name',Notes:'NOTES'}" ;
 var data2="{junk:'lll'}";
 data1=data1.concat(data2);

1 Comment

-1 you should at least try your code before answer a question jsfiddle.net/G8WLV

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.