mutable array methods in javascript

Solutions on MaxInterview for mutable array methods in javascript by the best coders in the world

showing results for - "mutable array methods in javascript"
Sebastián
08 Jul 2017
1/* array literal */
2var aData = [];
3
4/* object constructur */
5function Person(firstname, lastname) {
6  this.firstname = firstname;
7  this.lastname = lastname;
8  this.fullname = function() {
9    return (this.firstname + " " + this.lastname);
10  };
11}
12
13/* store object into array */
14aData[aData.length] = new Person("Java", "Script"); // aData[0]
15
16aData.push(new Person("Jhon", "Doe"));
17aData.push(new Person("Anna", "Smith"));
18aData.push(new Person("Black", "Pearl"));
19
20aData[aData.length] = new Person("stack", "overflow"); // aData[4]
21
22/* loop arrray */
23for (var i in aData) {
24  alert(aData[i].fullname());
25}
26
27/* convert array of object into string json */
28var jsonString = JSON.stringify(aData);
29document.write(jsonString);