// Javascript array method
var alert = function (str) {
var st = document.createTextNode(str);
var p = document.createElement('p');
p.appendChild(st);
document.querySelector('body').appendChild(p);
}
// concat()
var alpha = ["a", "b", "c"];
var numeric = [1, 2, 3];
var alphaNumeric = alpha.concat(numeric);
alert(alphaNumeric)
/* Javascript array filter() method creates a new array with all elements that pass the test implemented by the provided function */
function isBigEnough(element, index, array) {
return (element >= 10);
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
alert(filtered)
/*Javascript array indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present*/
var index = [12, 5, 8, 130, 44].indexOf(8);
alert(index)
var index = [12, 5, 8, 130, 44].indexOf(13);
alert(index)
/* Javascript array join() method joins all elements of an array into a string. */
var arr = new Array("First","Second","Third");
var str = arr.join();
alert(str)
/* Javascript array pop() method removes the last element from an array and returns that element. */
var number = [1,2,3,4]
var element = number.pop()
alert(element)
alert(number)
/* Javascript array push() method appends the given element(s) in the last of the array and returns the length of the new array. */
var element = number.push(2)
alert(element)
alert(number)
// Javascript array reverse() method reverses the element of an array.
var reverse = number.reverse()
alert(reverse)
// Javascript array sort() method sorts the elements of an array.
var sort = number.sort()
alert(sort)
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.