B
B
Boris Manzhela2016-04-15 17:00:45
JavaScript
Boris Manzhela, 2016-04-15 17:00:45

Insert object into object in Javascript?

Please tell me how to insert one object

var author = {
        name: 'Name',
        surneme: 'Surname'
    }

to another object
var mainObject = {
        title: ''
    };

so that we have the name of the embedded object become the key of the parent object, while receiving an object of the form
var mainObject = {
        title: '',
        author: {
            name: 'Name',
            surneme: 'Surname'
        }
    };


Using the [ ] notation or using $.extend did not work
. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2016-04-15
@EKCTPEMICT

mainObject.author = author;
learn.javascript.ru/object

E
Evgeny Kalibrov, 2015-03-25
@swipeshot

So the site returns data to you in windows-1251 encoding, so you either use it yourself, or do iconv after receiving a response. I just checked it through the console at http://huifikator.ru/api.php?text=hello , the response encoding is windows-1251

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question