javascript array of objects
//create array
var things = ["banana", "car", "computer"];
//access array(starts at 0)
things[0]
//iterate through an array
for (var i = 0; i < things.length; i++) {
things[i]
}The JavaScript filter() method has several components to its syntax.
newArray = initialArr.filter(callback);
newArray: you name the array that will consist of the filtered elements.
initialArr: the name of the original array.
callback: the method applied to the initialArr.
The callback can have three arguments as well:
element: the current element of the array.
index: the index number of the currently handled value.
array: the original array.
Therefore, the full syntax of the JavaScript array filter function would look like this:
newArray = initialArr.filter(callback(element, index, array));[element0, element1, ..., elementN]
new Array(element0, element1[, ...[, elementN]])
new Array(arrayLength)var cars = ["Saab", "Volvo", "BMW"];
var widgetTemplats = [
{
name: 'compass',
LocX: 35,
LocY: 312
},
{
name: 'another',
LocX: 52,
LocY: 32
}
]// Simple array of objects
var arr = [
{
first_name: 'Terry',
last_name: 'Tinseltits',
age: '47'
},
{
first_name: 'Frederick',
last_name: 'Foreskin',
age: '-1'
},
{
first_name: 'Wendy',
last_name: 'Wheelbarrow',
age: '84'
}
];
// Of course not, all the objects have to be the of the
// same type as in the above example