Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mutable array methods in javascript

/* array literal */
var aData = [];

/* object constructur */
function Person(firstname, lastname) {
  this.firstname = firstname;
  this.lastname = lastname;
  this.fullname = function() {
    return (this.firstname + " " + this.lastname);
  };
}

/* store object into array */
aData[aData.length] = new Person("Java", "Script"); // aData[0]

aData.push(new Person("Jhon", "Doe"));
aData.push(new Person("Anna", "Smith"));
aData.push(new Person("Black", "Pearl"));

aData[aData.length] = new Person("stack", "overflow"); // aData[4]

/* loop arrray */
for (var i in aData) {
  alert(aData[i].fullname());
}

/* convert array of object into string json */
var jsonString = JSON.stringify(aData);
document.write(jsonString);
Comment

PREVIOUS NEXT
Code Example
Javascript :: format to precision 2 javascript if double 
Javascript :: bootstrap react 
Javascript :: angular create library 
Javascript :: javascript hash table 
Javascript :: constant values javascript 
Javascript :: vue copy image to clipboard 
Javascript :: mongoose in node.js 
Javascript :: if window width jquery then display a div at scroll 
Javascript :: the sum of all first n natural numbers js 
Javascript :: how to convert string into binary in javascript 
Javascript :: select2 multi select get selected value 
Javascript :: accessing via name jquery 
Javascript :: jquery select input with empty value 
Javascript :: js use restrict 
Javascript :: react pass variable from child to parent 
Javascript :: javascript write to firebase 
Javascript :: react tabs 
Javascript :: isfunction javascript 
Javascript :: jsx babel webpack 
Javascript :: Select radio button through JQuery 
Javascript :: callback function js 
Javascript :: vscode react extensions 
Javascript :: react bootstrap sweetalert2 
Javascript :: JS how to determine if page was cached 
Javascript :: async function js 
Javascript :: json length javascript 
Javascript :: trigger jquery 
Javascript :: how to check if array 
Javascript :: .text javascript 
Javascript :: update angular project 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =