var name = new Array ("Greg");
var name = Array ("Greg");
var colors =["Red", "Blue", "green"];
Colors[colors.length] = "BLACK";
Console.log (colors.length,colors);
Colors.join (",");
Console.log (Colors.join (","));
Console.log (Colors.join ("| |)"); /array converted to string
var colors = new Array ();
var count = Colors.push ("Red", "green");//Add End
Console.log (count,colors);
Count = Colors.push ("Black", "gray");
Console.log (count,colors);
var item = Colors.pop (); End Delete Stack method (LIFO LIFO)
Console.log (item,colors.length);
var item2 = Colors.shift ();//front-end removal
Console.log (item2,typeof item2,item2.length,colors.length,colors);
var item3 = Colors.unshift ("yellow");//Front-end Add (FIFO first
Console.log (item3,colors);
var colors = new Array ();
var count = Colors.unshift ("Red", "green");
Console.log (count,colors);
Count =colors.unshift ("Black");
Console.log (count,colors);
var item = Colors.pop ();
Console.log (item,colors.length,colors);
var values=[1,2,3,4,5];
Values.reverse ();
Console.log (values);
var values = [0,1,5,10,15];
Values.reverse ();
Console.log (values);
var values = [0,1,5,10,15];
Values.sort ();
Console.log (5 <, "5" < "ten");//ture, false based on Unicode encoding comparison
Console.log (Values,values.tostring ());
This method
function Compare (value1,value2) {
if (value1 < value2) {
return-1;
Console.log (1);
}else if (value1 > value2) {
return 1;
Console.log (2);
}else{
return 0;
Console.log (3);
}
}
Values.sort (Compare)
Console.log (values);
A simpler approach
function Compare2 (value1,value2) {
return value2-value1;
}
Values.sort (Compare2);
Console.log (values);
/**concat
* Create a copy of the current array, and then add the accepted parameters to this copy of the
* At the end, a newly constructed array is returned.
*/
var colors = ["Red", "green", "blue", "Gray"];
/**concat
* Create a copy of the current array, and then add the accepted parameters to this copy of the
* At the end, a newly constructed array is returned.
*/
var colors = ["Red", "green", "blue", "Gray"];
var colors2 = Colors.concat ("Yellow", ["Black", "Brown"]);
Console.log (colors);
Console.log (COLORS2);
var cl = Colors.concat ();
Cl.push ("AA", "BB")
Console.log (COLORS,CL);
Slice creates a new array based on one or more items in the current array
var colors2 = Colors.slice (1);
var colors3 = Colors.slice (1,3);
var colors4 = Colors.slice ( -3,-1);//Start position is-3
Console.log (COLORS,COLORS2);
Console.log (COLORS3,COLORS4);
/**splice Delete (start, number of items deleted)
* Insert (Start, 0 "Number of items deleted", number of items to insert)
* Replace (start, number of items to be deleted, to insert any number of items)
*/
Console.log (colors);
var colors5 = Colors.splice (0,2);
var colors6 = Colors.splice (1,0, "AA", "BB", "CC");
var colors7 = Colors.splice (1,3, "yellow", "black", "white")
Console.log (colors);//
Console.log (COLORS5,COLORS6);//returns two items that are deleted
Console.log (COLORS,COLORS7);
/** Position Method IndexOf LastIndexOf
*
*/
var numbers = [1,2,3,4,5,4,3,2,1];
var nn=[]
Console.log (Numbers.indexof (3));
Nn.push (Numbers.indexof (3,1))
Console.log (Numbers.indexof (3,4));
Console.log (Numbers.lastindexof (1));
Console.log (Numbers.lastindexof (bis));
var person = {Name: "Nicholas"};
var people = [{name: ' Nicholas '}];
var Morepeople=[person];
Console.log (People.indexof (person));
Console.log (Morepeople.indexof (person));
Iterative methods
Returns true for each item.
var numbers = [1,2,3,4,5,4,3,2,1];
var everyresult = numbers.every (function (Item,index,array) {
Return (item > 2);
});
Console.log (Everyresult);
Returns TRUE if an item returns true for each of the given functions of the array.
var someresult = numbers.some (function (Item,index,array) {
Return (item > 2);
});
Console.log (Someresult);
Array for each item given a function, each of which returns true for the array of true entries
var filterresult = numbers.filter (function (Item,index,array) {
Console.log (Item,index,array);
Return (item > 2);
});
Console.log (Filterresult);
Array for each item given a function, each of which returns true for the array of true entries
var mapresult = Numbers.map (function (Item,index,array) {
Console.log (Item,index,array);
return (ITEM*2);
});
Console.log (Mapresult);
Array for each given function, no return value
var foreachreault = Numbers.foreach (function (Item,index,array) {
});
Console.log (Foreachreault);
JS Learning Note 5--reference type