vendredi 2 janvier 2015

Javascript: how to append sub-object into object?


Vote count:

0




I have tried several things, including using a constructor function, and the code below, none have worked. I thought this would be simple, how do I do this?



<!DOCTYPE html>
<html>
<body>

<p>Creating a JavaScript Object.</p>

<p id="demo"></p>

<script>
var name ={ // subobject
firstName : "John",
lastName : "Doe",
};
var person = {
name: {} // want to append here
};
person.name = name;
document.getElementById("demo").innerHTML =
person.name.firstName + " " + person.name.lastName;
</script>

</body>
</html>


asked 1 min ago







Javascript: how to append sub-object into object?

Aucun commentaire:

Enregistrer un commentaire