dee cheok dee cheok - 9 months ago 29
jQuery Question

put value into a object in order

var dataArray = [];

function setUpData (){
name.val();
address.val();
age.val();
phone.val();

var dataObj = {name, address, age, phone};

dataObj[name] = name.val();
dataObj[address] = address.val();
dataObj[age] = age.val();
dataObj[phone] = phone.val();

dataArray.push(dataObj);

}


i wanted to store my data to obj and then append into array , so i am append want the object to look like this name : jason , age : 27 , something like that, but i am having error doing this.

how i gonna to achieve that ?

Answer Source

create an array (exactly like you did):

var dataArray = [];

create the object you want:

var person = new Object();
    person.name = 'Jason';
    person.age = 35;

add it to the array

dataArray.push(person);